|
Hello !!!
I need help !
I would like to know how I can operate a mp3 when an event is ocour. What is the code line ?
Thank You !!!
Ahuva
|
|
|
|
|
Help Please...!
I'm trying to add a shutdown routine to a program using the ExitWindowsEx API function. I'm running on Windows XP. The problem is that the LookUpPrivilegeValue function keeps crashing out saying : Instance of an object is not set. As far as I know I'm not referencing an object merely calling a function. Can anyone help?
Here is the code I am using:
Option Explicit On
Imports System
Imports System.Runtime.InteropServices
Public Class ShutDownAPI
Private Const EWX_LogOff As Long = 0
Private Const EWX_SHUTDOWN As Long = 1
Private Const EWX_REBOOT As Long = 2
Private Const EWX_FORCE As Long = 4
Private Const EWX_POWEROFF As Long = 8
<dllimport("user32.dll")> Public Shared Function ExitWindowsEx(ByVal dwOptions As Long, ByVal dwReserved As Long) As Long
End Function
<dllimport("kernel32.dll")> Public Shared Function GetLastError() As Long
End Function
<dllimport("kernel32.dll")> Public Shared Function GetVersion() As Long
End Function
<dllimport("kernel32.dll")> Public Shared Function GetCurrentProcess() As Long
End Function
<dllimport("advapi32.dll")> Public Shared Function OpenProcessToken(ByVal ProcessHandle As Long, ByVal DesiredAccess As Long, ByVal TokenHandle As Long) As Long
End Function
Private Declare Function LookupPrivilegeValue Lib "advapi32.dll" Alias "LookupPrivilegeValueA" (ByVal lpSystemName As String, ByVal lpName As String, ByVal lpLuid As LUID) As Long
<dllimport("advapi32.dll")> Public Shared Function AdjustTokenPrivileges(ByVal TokenHandle As Long, ByVal DisableAllPrivileges As Long, ByVal NewState As TOKEN_PRIVILEGES, ByVal BufferLength As Long, ByVal PreviousState As TOKEN_PRIVILEGES, ByVal ReturnLength As Long) As Long
End Function
<dllimport("kernel32.dll")> Public Shared Sub SetLastError(ByVal dwErrCode As Long)
End Sub
Private Const mlngWindows95 = 0
Private Const mlngWindowsNT = 1
Private glngWhichWindows32 As Long
Public Structure LUID
Public UsedPart As Long
Public IgnoredForNowHigh32BitPart As Long
End Structure
Public Structure LUID_AND_ATTRIBUTES
Public TheLuid As LUID
Public Attributes As Long
End Structure
Public Structure TOKEN_PRIVILEGES
Public PrivilegeCount As Long
Public TheLuid As LUID
Public Attributes As Long
End Structure
Public Enum sdAction
Reboot = 1
Shutdown = 2
Logoff = 3
End Enum
Private Sub AdjustToken()
Const TOKEN_ADJUST_PRIVILEGES = &H20
Const TOKEN_QUERY = &H8
Const SE_PRIVILEGE_ENABLED = &H2
Dim hdlProcessHandle As Long
Dim hdlTokenHandle As Long
Dim tmpLuid As New APITest2.TestAPI.LUID()
Dim tkp As New TOKEN_PRIVILEGES()
Dim tkpNewButIgnored As New TOKEN_PRIVILEGES()
Dim lBufferNeeded As Long
SetLastError(0)
hdlProcessHandle = GetCurrentProcess()
OpenProcessToken(hdlProcessHandle, (TOKEN_ADJUST_PRIVILEGES Or TOKEN_QUERY), hdlTokenHandle)
LookupPrivilegeValue("", "SeShutdownPrivilege", tmpLuid)
tkp.PrivilegeCount = 1 ' One privilege to set
tkp.TheLuid = tmpLuid
tkp.Attributes = SE_PRIVILEGE_ENABLED
AdjustTokenPrivileges(hdlTokenHandle, False, tkp, Len(tkpNewButIgnored), tkpNewButIgnored, lBufferNeeded)
End Sub
Public Sub ExitWin(ByVal Act As sdAction, ByVal Force As Boolean)
Dim iAction As Integer
AdjustToken()
If Act = sdAction.Logoff Then iAction = EWX_LogOff
If Act = sdAction.Reboot Then iAction = EWX_REBOOT
If Act = sdAction.Shutdown Then iAction = EWX_SHUTDOWN
If Force = True Then
ExitWindowsEx((iAction Or EWX_FORCE), CLng(&HFFFF))
Else
ExitWindowsEx(iAction, CLng(&HFFFF))
End If
End Sub
Public Sub New()
Dim lngVersion As Long
lngVersion = GetVersion()
If ((lngVersion And &H80000000) <> 0) Then
glngWhichWindows32 = mlngWindowsNT
Else
glngWhichWindows32 = mlngWindows95
End If
End Sub
End Class
Using the ExitWin Sub to call the shutdown procedeure. Any Ideas
|
|
|
|
|
Change your definition of LookupPrivilegeValue to this:
Public Declare Function LookupPrivilegeValue Lib "advapi32.dll" Alias "LookupPrivilegeValueA" (ByVal lpSystemName As String, ByVal lpName As String, lpLuid As LARGE_INTEGER) As Long
and LARGE_INTEGER is declared liek this:
Public Type LARGE_INTEGER
lowpart As Long
highpart As Long
End Type
Use the APIViewer tool in VB to create these function declarations for you.
Good luck.
Build a man a fire, and he will be warm for a day Light a man on fire, and he will be warm for the rest of his life!
|
|
|
|
|
How can I access the DHTML objects from an activex created from new ActiveXObject("") jscript method?
Or I can just do this if I create an activex control?
thanks,
Luiz
|
|
|
|
|
You have a reference the ActiveX control first in Project/References.
JScript Example:
var objSession = new ActiveXObject("MAPI.Session"); VB Example:
Dim objSession As MAPI.Session
Set objSession = New MAPI.Session
Jeremy L. Falcon
"The One Who Said, 'The One Who Said...'"
<nobr>
Homepage : Sonork = 100.16311 01000010011011110110001000100000011101110110000101110011 00100000011010000110010101110010011001010010111000000000
|
|
|
|
|
I made an VBA Add-In template in MS Word 2000. Is there any way i could make it work in MS Word 97, too? Ive tried to use it in Word 97 but it gave me an error message saying it wont compile... Can anyone help?
|
|
|
|
|
How could I put a array of bytes into a file ???
|
|
|
|
|
Dim b() as Byte
'Do something with b
Open "filename.txt" For Binary As #1
Put #1, , b
Close #1
Should work...
--
David Wengier
Sonork ID: 100.14177 - Ch00k
|
|
|
|
|
I don't know if you mean this, sorry if don't
Open "outputfile" for output as #1
For intI = 1 to ubound(arrArrayName)
print #1, arrArrayName(intI)
Next intI
Close 1
See:
Syntax
Open pathname For mode [Access access] [lock] As [#]filenumber [Len=reclength]
The Open statement syntax has these parts:
Part Description
pathname Required. String expression that specifies a file name — may include directory or folder, and drive.
mode Required. Keyword specifying the file mode: Append, Binary, Input, Output, or Random. If unspecified, the file is opened for Random access.
access Optional. Keyword specifying the operations permitted on the open file: Read, Write, or Read Write.
lock Optional. Keyword specifying the operations restricted on the open file by other processes: Shared, Lock Read, Lock Write, and Lock Read Write.
filenumber Required. A valid file number in the range 1 to 511, inclusive. Use the FreeFile function to obtain the next available file number.
reclength Optional. Number less than or equal to 32,767 (bytes). For files opened for random access, this value is the record length. For sequential files, this value is the number of characters buffered.
Fernando Finelli
|
|
|
|
|
I am not very familar with Microsoft Access,but it seems that when you encrypt a access file(in menu tool->security),you needn't enter a username.Now the problem come:
In VB6.0,how can i connect to such a encrypted file?By data control,i didn't find any property related to database security;by ADO,the connection string shall contain a username,but what's the username to such a file?I tried leave it empty,but it caused a error
|
|
|
|
|
Hi all,
I've got problem when I try using Visual Basic 6.0 to display Unicode font on menu bar. Some characters appear with the question-marks.
If you'd done well this issue, please show me. I'm looking forward to your replies. Thanks a lot for your help.
Vu Truong.
|
|
|
|
|
This is a little difficult, you will need to resort to the Windows API's in order to do this.
You will need to look into localization functions to properly set the locale of the strings that your are working with. I do not have any more information than that right now, but I will try to post a link later today.
I hope this gets you started.
Build a man a fire, and he will be warm for a day Light a man on fire, and he will be warm for the rest of his life!
|
|
|
|
|
This is to all the excel geniuses, am trying to limit the lenght of text in a dailog box(in excel) if you think u can help plz reply
Thanks
|
|
|
|
|
I assume you are using a textbox. Just set the MaxLength property to the length you need. You can do this in the properties window (right click the text box and select Properties) or in code (Userform1.Textbox1.MaxLength = xx in the initialize procedure).
|
|
|
|
|
How do you create a new User Defined function for Crystal.Net?
|
|
|
|
|
|
I want put array of 400 byte into a field in Access Table from my code (VB).
How ???
|
|
|
|
|
I'm new to VB,anybody can tell me how to add items(root,and child) to a TreeView control?
thanks
|
|
|
|
|
TreeView1.Nodes.Add , , "root", "Root Node"
TreeView1.Nodes.Add "root", tvwChild, "child1", "Child 1"
TreeView1.Nodes.Add "root", tvwChild, "child2", "Child 2"
TreeView1.Nodes.Add "root", tvwChild, "child3", "Child 3"
TreeView1.Nodes.Add "root", tvwChild, "child4", "Child 4"
TreeView1.Nodes.Add "child3", tvwChild, "child3.1", "Child 3.1"
Also, try looking on MSDN, it will tell you a lot more.
--
David Wengier
Sonork ID: 100.14177 - Ch00k
|
|
|
|
|
I have one:
http://www.codeproject.com/useritems/ASPTreeView.asp
Fernando Finelli
|
|
|
|
|
Speech to text Example is not working....I am working on win'98 with vb 6.0 and the code doesnt work..ie the speech output isnt there.Even in the supplied example.Any ideas......
|
|
|
|
|
I have used ActiveX ctrl to asynchronously download a file from FTP site. Program downloads the file for the first time from the site.But,next time it dont download file from the site.I think,It gets the file from cached in c:\winnt\profiles\myNTlogin\temporary internet files.when delete the file from there,next time program downloads from site.
I have used :
flag=fs.FileExists("c:\winnt\profiles\myNTlogin\temporary internet files\file")
Although, the file is there, function returns FALSE.
Can anybody tell me How to delete that temporary file programatically,
Thanks in advance
|
|
|
|
|
C# has an events button in the properties window, but VB.NET doesn't.
WTF?
How do you get to choose the event of a eg: command button?
Cheers,
Simon
X-5 452 rules.
|
|
|
|
|
In the code editor, there are two drop downs at the top of the window. In the left one, pick the object (or overrides, interface, base events etc.) that you want, and then in the right one, pick the event/method.
Or, for events, just start typeing:
Private Sub DoSomething(sender as object, e as EventArgs) Handles
as soon as you press the space bar after Handles, IntelliSense will pop up a list of objects, and away you go.
--
David Wengier
Sonork ID: 100.14177 - Ch00k
|
|
|
|
|
Thanks, I'll pass it on to my team.
Cheers,
Simon
X-5 452 rules.
|
|
|
|
|