Hej Thomas
Hvis du har administrator rettigheder på dit netværk, kan du bare åbne stifinder skrive \\maskinenavn\c$ i adresse felt, og du har nu adgang til c drev på denne maskine, så kan du jo lege alt det du vil med denne maskine.
Regedit kan også åbnes andre maskiner registreringsdatabase.
Her på dette site kan du finde noget legetøj
http://www.sysinternals.com
Mvh.
Flemming
Here er lidt kode til reboot en maskine over netværk
Lav en form "Parameter" med beskrivelse af parameterne.
/M: Message
/N: Servername ( if no name, then this server )
/S: sec. to wait for a shutdown/reboot
/C Close all application before shutdown/Reboot
/R Reboot
Ex.
NT_Shutdown /M:'10 sec. to server reboot' /N:Exchange /S:10 /C /R
Lav et Modul "Reboot" med flg. kode
Option Explicit
Dim Aktiv As Boolean
' To Determine if we are running NT or not:
Private Type OSVERSIONINFO
dwOSVersionInfoSize As Long
dwMajorVersion As Long
dwMinorVersion As Long
dwBuildNumber As Long
dwPlatformId As Long
szCSDVersion As String * 128 ' Maintenance string for PSS usage
End Type
Private Declare Function GetVersionEx Lib "kernel32" Alias _
"GetVersionExA" (lpVersionInformation As OSVERSIONINFO) As Long
Private Const VER_PLATFORM_WIN32_NT = 2
Private Const VER_PLATFORM_WIN32_WINDOWS = 1
Private Const VER_PLATFORM_WIN32s = 0
' To Report API errors:
Private Const FORMAT_MESSAGE_ALLOCATE_BUFFER = &H100
Private Const FORMAT_MESSAGE_ARGUMENT_ARRAY = &H2000
Private Const FORMAT_MESSAGE_FROM_HMODULE = &H800
Private Const FORMAT_MESSAGE_FROM_STRING = &H400
Private Const FORMAT_MESSAGE_FROM_SYSTEM = &H1000
Private Const FORMAT_MESSAGE_IGNORE_INSERTS = &H200
Private Const FORMAT_MESSAGE_MAX_WIDTH_MASK = &HFF
Private Declare Function FormatMessage Lib "kernel32" Alias _
"FormatMessageA" (ByVal dwFlags As Long, lpSource As Any, _
ByVal dwMessageId As Long, ByVal dwLanguageId As Long, _
ByVal lpBuffer As String, ByVal nSize As Long, _
Arguments As Long) As Long
' Win NT Only
Private Type LARGE_INTEGER
LowPart As Long
HighPart As Long
End Type
Private Type LUID
LowPart As Long
HighPart As Long
End Type
Private Type LUID_AND_ATTRIBUTES
pLuid As LUID
Attributes As Long
End Type
Private Type TOKEN_PRIVILEGES
PrivilegeCount As Long
Privileges(0 To 0) As LUID_AND_ATTRIBUTES
End Type
Private Declare Function GetCurrentProcess Lib "kernel32" () As Long
Private Declare Function OpenProcessToken Lib "advapi32.dll" _
(ByVal ProcessHandle As Long, ByVal DesiredAccess As Long, _
TokenHandle As Long) As Long
Private Declare Function CloseHandle Lib "kernel32" _
(ByVal hObject As Long) As Long
Private Declare Function GetTokenInformation Lib "advapi32.dll" _
(ByVal TokenHandle As Long, TokenInformationClass As Integer, _
TokenInformation As Any, ByVal TokenInformationLength As Long, _
ReturnLength As Long) As Long
Private Declare Function AdjustTokenPrivileges Lib "advapi32.dll" _
(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 Function LookupPrivilegeValue Lib "advapi32.dll" _
Alias "LookupPrivilegeValueA" (ByVal lpSystemName As String, _
ByVal lpName As String, lpLuid As LUID) As Long
Private Const SE_SHUTDOWN_NAME = "SeShutdownPrivilege"
Private Const SE_PRIVILEGE_ENABLED = &H2
Private Const READ_CONTROL = &H20000
Private Const STANDARD_RIGHTS_ALL = &H1F0000
Private Const STANDARD_RIGHTS_EXECUTE = (READ_CONTROL)
Private Const STANDARD_RIGHTS_READ = (READ_CONTROL)
Private Const STANDARD_RIGHTS_REQUIRED = &HF0000
Private Const STANDARD_RIGHTS_WRITE = (READ_CONTROL)
Private Const TOKEN_ASSIGN_PRIMARY = &H1
Private Const TOKEN_DUPLICATE = (&H2)
Private Const TOKEN_IMPERSONATE = (&H4)
Private Const TOKEN_QUERY = (&H8)
Private Const TOKEN_QUERY_SOURCE = (&H10)
Private Const TOKEN_ADJUST_PRIVILEGES = (&H20)
Private Const TOKEN_ADJUST_GROUPS = (&H40)
Private Const TOKEN_ADJUST_DEFAULT = (&H80)
Private Const TOKEN_ALL_ACCESS = (STANDARD_RIGHTS_REQUIRED Or _
TOKEN_ASSIGN_PRIMARY Or _
TOKEN_DUPLICATE Or _
TOKEN_IMPERSONATE Or _
TOKEN_QUERY Or _
TOKEN_QUERY_SOURCE Or _
TOKEN_ADJUST_PRIVILEGES Or _
TOKEN_ADJUST_GROUPS Or _
TOKEN_ADJUST_DEFAULT)
Private Const TOKEN_READ = (STANDARD_RIGHTS_READ Or _
TOKEN_QUERY)
Private Const TOKEN_WRITE = (STANDARD_RIGHTS_WRITE Or _
TOKEN_ADJUST_PRIVILEGES Or _
TOKEN_ADJUST_GROUPS Or _
TOKEN_ADJUST_DEFAULT)
Private Const TOKEN_EXECUTE = (STANDARD_RIGHTS_EXECUTE)
Private Const TokenDefaultDacl = 6
Private Const TokenGroups = 2
Private Const TokenImpersonationLevel = 9
Private Const TokenOwner = 4
Private Const TokenPrimaryGroup = 5
Private Const TokenPrivileges = 3
Private Const TokenSource = 7
Private Const TokenStatistics = 10
Private Const TokenType = 8
Private Const TokenUser = 1
Private Declare Function InitiateSystemShutdown Lib "advapi32.dll" _
Alias "InitiateSystemShutdownA" (ByVal lpMachineName As String, _
ByVal lpMessage As String, ByVal dwTimeout As Long, _
ByVal bForceAppsClosed As Long, _
ByVal bRebootAfterShutdown As Long) As Long
Private Declare Function AbortSystemShutdown Lib "advapi32.dll" _
Alias "AbortSystemShutdownA" (ByVal lpMachineName As String) _
As Long
Private Const eeSSDErrorBase = 0
Public Function WinError(ByVal lLastDLLError As Long) As String
Dim sBuff As String
Dim lCount As Long
' Return the error message associated with LastDLLError:
sBuff = String$(256, 0)
lCount = FormatMessage(FORMAT_MESSAGE_FROM_SYSTEM Or _
FORMAT_MESSAGE_IGNORE_INSERTS, 0, lLastDLLError, 0&, _
sBuff, Len(sBuff), ByVal 0)
If lCount Then
WinError = Left$(sBuff, lCount)
End If
End Function
Public Function IsNT() As Boolean
Static bOnce As Boolean
Static bValue As Boolean
' Return whether the system is running NT or not:
If Not (bOnce) Then
Dim tVI As OSVERSIONINFO
tVI.dwOSVersionInfoSize = Len(tVI)
If (GetVersionEx(tVI) <> 0) Then
bValue = (tVI.dwPlatformId = VER_PLATFORM_WIN32_NT)
bOnce = True
End If
End If
IsNT = bValue
End Function
Private Function NTEnableShutDown(ByRef sMsg As String) As Boolean
Dim tLUID As LUID
Dim hProcess As Long
Dim hToken As Long
Dim tTP As TOKEN_PRIVILEGES, tTPOld As TOKEN_PRIVILEGES
Dim lTpOld As Long
Dim lR As Long
' Under NT we must enable the SE_SHUTDOWN_NAME privilege in the
' process we're trying to shutdown from, otherwise a call to
' try to shutdown has no effect!
' Find the LUID of the Shutdown privilege token:
lR = LookupPrivilegeValue(vbNullString, SE_SHUTDOWN_NAME, tLUID)
' If we get it:
If (lR <> 0) Then
' Get the current process handle:
hProcess = GetCurrentProcess()
If (hProcess <> 0) Then
' Open the token for adjusting and querying (if
' we can - user may not have rights):
lR = OpenProcessToken(hProcess, TOKEN_ADJUST_PRIVILEGES _
Or TOKEN_QUERY, hToken)
If (lR <> 0) Then
' Ok we can now adjust the
' shutdown priviledges:
With tTP
.PrivilegeCount = 1
With .Privileges(0)
.Attributes = SE_PRIVILEGE_ENABLED
.pLuid.HighPart = tLUID.HighPart
.pLuid.LowPart = tLUID.LowPart
End With
End With
' Now allow this process to shutdown the system:
lR = AdjustTokenPrivileges(hToken, 0, tTP, Len(tTP), _
tTPOld, lTpOld)
If (lR <> 0) Then
NTEnableShutDown = True
Else
Err.Raise eeSSDErrorBase + 6, App.EXEName & ".mShutDown", _
"Can't enable shutdown: You do not have the privileges to shutdown this system. [" & _
WinError(Err.LastDllError) & "] """
End If
' Remember to close the handle when finished with it:
CloseHandle hToken
Else
Err.Raise eeSSDErrorBase + 6, App.EXEName & ".mShutDown", _
"Can't enable shutdown: You do not have the privileges to shutdown this system. [" & _
WinError(Err.LastDllError) & "]"
End If
Else
Err.Raise eeSSDErrorBase + 5, App.EXEName & ".mShutDown", _
"Can't enable shutdown: Can't determine the current process. [" & _
WinError(Err.LastDllError) & "]"
End If
Else
Err.Raise eeSSDErrorBase + 4, App.EXEName & ".mShutDown", _
"Can't enable shutdown: Can't find the SE_SHUTDOWN_NAME privilege value. [" & _
WinError(Err.LastDllError) & "]"
End If
End Function
Public Function NTForceTimedShutdown _
(Optional ByVal lTimeOut As Long = -1, _
Optional ByVal sMsg As String = "", _
Optional ByVal sMachineNetworkName As String = vbNullString, _
Optional ByVal bForceAppsToClose As Boolean = False, _
Optional ByVal bReboot As Boolean = False) As Boolean
Dim lR As Long
If IsNT Then
' Make sure we have enabled the privilege to shutdown
' for this process if we're running NT:
If Not (NTEnableShutDown(sMsg)) Then
Exit Function
End If
' This is the code to do a timed shutdown:
lR = InitiateSystemShutdown(sMachineNetworkName, sMsg, _
lTimeOut, bForceAppsToClose, bReboot)
If (lR = 0) Then
Err.Raise eeSSDErrorBase + 2, App.EXEName & ".mShutDown", _
"InitiateSystemShutdown failed: " & _
WinError(Err.LastDllError)
End If
Else
Err.Raise eeSSDErrorBase + 1, App.EXEName & ".mShutDown", _
"Function only available under Windows NT."
End If
End Function
Public Function NTAbortTimedShutdown(Optional ByVal sMachineNetworkName _
As String = vbNullString)
AbortSystemShutdown sMachineNetworkName
End Function
Sub Main()
Dim X, A, D(4)
D(0) = "0" 'Sec.
D(1) = "" 'Message
D(2) = "" 'Server name
D(3) = False ' Close all application before shutdown/Reboot
D(4) = False ' Shutdown / Reboot
X = GetCommandLine
If X(0) > 0 Then
For A = 1 To X(0)
Select Case Mid(UCase(X(A)), 1, 2)
Case "/M"
D(1) = Mid(X(A), 4, Len(X(A)) - 3)
Case "/N"
D(2) = Mid(X(A), 4, Len(X(A)) - 3)
Case "/S"
D(0) = Mid(X(A), 4, Len(X(A)) - 3)
Case "/C"
D(3) = True
Case "/R"
D(4) = True
Case Else
Load Parameter
Parameter.Visible = True
End Select
Next
End If
If Not Parameter.Visible Then
NTForceTimedShutdown D(0), D(1), D(2), D(3), D(4)
End
End If
End Sub
Function GetCommandLine(Optional MaxArgs)
'Declare variables.
Dim C, CmdLine, CmdLnLen, InArg, i, NumArgs, Tekst As Boolean
'See if MaxArgs was provided.
If IsMissing(MaxArgs) Then MaxArgs = 10
'Make array of the correct size.
ReDim ArgArray(MaxArgs)
NumArgs = 0: InArg = False
'Get command line arguments.
CmdLine = Command()
CmdLnLen = Len(CmdLine)
'Go thru command line one character
'at a time.
For i = 1 To CmdLnLen
C = Mid(CmdLine, i, 1)
'Test for space or tab.
If (C <> " " And C <> vbTab) Then
'Neither space nor tab.
'Test if already in argument.
If C = "'" Then
If Tekst Then
Tekst = False
Else
Tekst = True
End If
Else
If Not InArg Then
'New argument begins.
'Test for too many arguments.
If NumArgs = MaxArgs Then Exit For
NumArgs = NumArgs + 1
InArg = True
End If
'Concatenate character to current argument.
ArgArray(NumArgs) = ArgArray(NumArgs) & C
End If
Else
'Found a space or tab.
'Set InArg flag to False.
If Not Tekst Then
InArg = False
Else
ArgArray(NumArgs) = ArgArray(NumArgs) & C
End If
End If
Next i
'Resize array just enough to hold arguments.
ReDim Preserve ArgArray(NumArgs)
'Return Array in Function name.
ArgArray(0) = NumArgs
GetCommandLine = ArgArray()
End Function
Set dit projekt til at start med "Main" (Startup Object = sub main)