Autor | Thema: Shutdown WindowsNT | | Datum:25.11.01 20:23 
(thinninger@email.com) | |
Moin, Moin..
Ich möchte NT4.0 oder Win2K über eine Profan Routine herunterfahren. Dies klappt wunderbar mit Win9x/Me. Dort muss ich auch nicht nach den Privilegien fragen.
Anbei findet ihr ein VB-Source-Code, in dem das herunterfahren funktioniert. Sowie einen Versuch das ganze in eine Profan Routine zu packen, bei der wahrscheinlich alles Falsch ist, da ich immer noch nicht verstanden habe, wie man Bereiche für einen API-Aufruf definiert.
Profan:
declare EWX_LogOff&
declare EWX_SHUTDOWN&
declare EWX_REBOOT&
declare EWX_FORCEtoLogOff&
declare EWX_FORCEtoSHUTDOWN&
declare mlngWindows95&
declare mlngWindowsNT&
declare glngWhichWindows32&
declare Bereich#
declare Bereich1#
declare Bereich2#
declare how$
how$ = "0"
EWX_LogOff& = 0
EWX_SHUTDOWN& = 1
EWX_REBOOT& = 2
EWX_FORCEtoLogOff& = 4
EWX_FORCEtoSHUTDOWN& = 5
mlngWindows95& = 0
mlngWindowsNT& = 1
STRUCT LUID = UsedPart&, IgnoredFNH32BP&
Dim Bereich#,LUID
STRUCT LUID_AND_ATTRIBUTES = UsedPart&, IgnoredFNH32BP&, Attributes&
Dim Bereich1#,LUID_AND_ATTRIBUTES
STRUCT TOKEN_PRIVILEGES = PrivilegeCount&, UsedPart&, IgnoredFNH32BP&, Attributes&
Dim Bereich2#,TOKEN_PRIVILEGES
DEF @ExitWindowsEx(2) !"USER32", "ExitWindowsEx"
DEF @GetLastError(0) !"kernel32", "GetLastError"
DEF @GetVersion(0) !"kernel32", "GetVersion"
DEF @GetCurrentProcess(0) !"kernel32", "GetCurrentProcess"
DEF @OpenProcessToken(3) !"advapi32", "OpenProcessToken"
DEF @LookupPrivilegeValue(3) !"advapi32", "LookupPrivilegeValueA"
DEF @AdjustTokenPrivileges(6) !"advapi32", "AdjustTokenPrivileges"
DEF @SetLastError(0) !"kernel32", "SetLastError"
proc AdjustToken
DEF &TOKEN_ADJUST_PRIVILEGES = $28
DEF &TOKEN_QUERY = $8
DEF &SE_PRIVILEGE_ENABLED = $2
declare hdlProcessHandle&
declare hdlTokenHandle&
declare tmpLuid#
declare tkp#
declare tkpNewButIgnored#
declare lBufferNeeded&
Dim tmpLuid#,LUID
Dim tkp#,TOKEN_PRIVILEGES
Dim tkpNewButIgnored#,TOKEN_PRIVILEGES
' SetLastError() 0
hdlProcessHandle& = GetCurrentProcess()
OpenProcessToken(hdlProcessHandle&,&TOKEN_ADJUST_PRIVILEGES, hdlTokenHandle&)
LookupPrivilegeValue("", "SeShutdownPrivilege", tmpLuid#)
tkp#.PrivilegeCount& = 1
tkp#.UsedPart& = tmpLuid#.UsedPart&
tkp#.IgnoredFNH32BP& = tmpLuid#.IgnoredFNH32BP&
tkp#.Attributes& = &SE_PRIVILEGE_ENABLED
AdjustTokenPrivileges(hdlTokenHandle&, -1, tkp# ,len(tkpNewButIgnored#),tkpNewButIgnored# , lBufferNeeded&)
endproc
proc HowToEnd
declare success&
Case @Equ$(How$,"0"): success& = ExitWindowsEx(EWX_SHUTDOWN&, 65535)
Case @Equ$(How$,"1"): success& = ExitWindowsEx(EWX_LogOff&, 65535)
Case @Equ$(How$,"2"): success& = ExitWindowsEx(EWX_FORCEtoLogOff&, 65535)
Case @Equ$(How$,"3"): success& = ExitWindowsEx(EWX_REBOOT&, 65535)
Case @Equ$(How$,"4"): success& = ExitWindowsEx(EWX_FORCEtoSHUTDOWN&, 65535)
endproc
AdjustToken
howtoend
VB5 oder VB6:
Option Explicit
Dim hans As Variant
Public Enum tExWin
EWX_LogOff = 0
EWX_SHUTDOWN = 1
EWX_REBOOT = 2
EWX_FORCEtoLogOff = 4
EWX_FORCEtoSHUTDOWN = 8
End Enum
'The ExitWindowsEx function either logs off, shuts down, or shuts
'down and restarts the system.
Private Declare Function ExitWindowsEx Lib "user32" _
(ByVal dwOptions As Long, _
ByVal dwReserved As Long) As Long
'The GetLastError function returns the calling thread's last-error
'code value. The last-error code is maintained on a per-thread basis.
'Multiple threads do not overwrite each other's last-error code.
Private Declare Function GetLastError Lib "kernel32" () As Long
Private Const mlngWindows95 = 0
Private Const mlngWindowsNT = 1
Public glngWhichWindows32 As Long
'The GetVersion function returns the operating system in use.
Private Declare Function GetVersion Lib "kernel32" () As Long
Private Type LUID
UsedPart As Long
IgnoredForNowHigh32BitPart As Long
End Type
Private Type LUID_AND_ATTRIBUTES
TheLuid As LUID
Attributes As Long
End Type
Private Type TOKEN_PRIVILEGES
PrivilegeCount As Long
TheLuid As LUID
Attributes As Long
End Type
'The GetCurrentProcess function returns a pseudohandle for the
'current process.
Private Declare Function GetCurrentProcess Lib "kernel32" () As Long
'The OpenProcessToken function opens the access token associated with
'a process.
Private Declare Function OpenProcessToken Lib "advapi32" _
(ByVal ProcessHandle As Long, _
ByVal DesiredAccess As Long, _
TokenHandle As Long) As Long
'The LookupPrivilegeValue function retrieves the locally unique
'identifier (LUID) used on a specified system to locally represent
'the specified privilege name.
Private Declare Function LookupPrivilegeValue Lib "advapi32" _
Alias "LookupPrivilegeValueA" _
(ByVal lpSystemName As String, _
ByVal lpName As String, _
lpLuid As LUID) As Long
'The AdjustTokenPrivileges function enables or disables privileges
'in the specified access token. Enabling or disabling privileges
'in an access token requires TOKEN_ADJUST_PRIVILEGES access.
Private Declare Function AdjustTokenPrivileges Lib "advapi32" _
(ByVal TokenHandle As Long, _
ByVal DisableAllPrivileges As Long, _
NewState As TOKEN_PRIVILEGES, _
ByVal BufferLength As Long, _
PreviousState As TOKEN_PRIVILEGES, _
ReturnLength As Long) As Long
Private Declare Sub SetLastError Lib "kernel32" _
(ByVal dwErrCode As Long)
Private Sub AdjustToken()
'********************************************************************
'* This procedure sets the proper privileges to allow a log off or a
'* shut down to occur under Windows NT.
'********************************************************************
Const TOKEN_ADJUST_PRIVILEGES = &H28
Const TOKEN_QUERY = &H8
Const SE_PRIVILEGE_ENABLED = &H2
Dim hdlProcessHandle As Long
Dim hdlTokenHandle As Long
Dim tmpLuid As LUID
Dim tk
|
| | Datum:20.12.01 14:52 
(Rupert_Mueller@t-online.de) | |
Hallo Thomas,
da ich ein zeimlich fauler typ bin ruf ich am ende meines Profan Programms mit "winexec" einfach das Programm shutdown.exe aus dem Windows NT Resource Kit auf ...
(mit Timer, funktioniert sogar mit remote Computer im Netzwerk, etc!)
hier die Beschreibung:
--------------------------------------------------------------------------------
shutdown [\\computername] [/l] [/a] [/r] [/t:xx] ["msg"] [/y] [/c] [/?]
Where:
\\computername
Local or remote computer to shut down. If no name is given but the tool is started with any of the other options, the local computer name will be used.
/L
Specifies a local shutdown.
/A
Quits a system shutdown. This can only be done during the timeout period. If this switch is used, all others are ignored.
/R
Restart the computer specifed after shutdown.
/T:xx
Sets the timer for system shutdown in xx seconds. The default is 20 seconds.
"msg"
Specifies an additional message with a maximum of 127 characters, surrounded by quotation marks.
/y
Answers questions with "yes".
/C
Forces running applications to close.
Caution
If you use the /c parameter, Windows 2000 ignores the application's option to save data that might have changed. You will see no File Save dialog box, because Windows 2000 will force the application to close. This will result in a loss of all data not previously saved.
/? (or shutdown without parameters)
Display help.
Examples
Shutdown and reboot a remote computer.
shutdown \\IMAREMOTECOMPUTER /R
Shutdown a local computer, closing all applications in 5 seconds.
shutdown /L /C /T:5
_____________________
Zugegeben nicht die feine Profanart ...grins
Rupert
|
| | Datum:20.12.01 20:27 
(thinninger@email.com) | |
Danke für die Antwort. Nach allem Suchen ist dies wohl die Lösung für mich...Sir schöne Festtage
|
| | Datum:20.12.01 23:54 
(writer@stories.short.de) | |
Hallo,
was ist aber, wenn das RSK nicht installiert ist? Habe nämlich dasselbe Problem und kann lediglich einen neuen Benutzer anmelden lassen. Geht das vielleicht auch "richtig"?
BriS
|
| | Datum:22.12.01 11:39 
(Rupert_Mueller@t-online.de) | |
Servus Britta,
was willst Du denn genau machen? Geht es um die Anmeldung an anderen Clients o.ä.?
Wenn 's um Netzwerkadministration geht, bitte direkt an meine Emailadresse ...
Rupert
|
| | Datum: 13.01.02 00:50 
(rgh-soft@t-online.de) | |
Auch das Shut-Down-Problem (EXITWINDOWS) unter Windows NT/2000/XP wird in PROFAN 7.5 gelöst sein!
|
|
|