Hilfe im VB Scripten
Hallo Zusammen,
ich bin der absolute Laie in VB und bräuchte dringend Hilfe
Hallo Zusammen,
ich habe im Internet 2 Scripts gefunden um meine Win7 Rechner umzubenennen und und in meine Domäne zu heben. Beide Scripte werfen verschiedene Fehler aus - Fehler 0 usw Fehler.... in dem anderen Script.
Wer kann mir dabei helfen ?
Hier die Scripts:
<Script1>
Const JOIN_DOMAIN = 1
Const ACCT_CREATE = 2
Dim sCmpName
Dim sUser, sPassword, sDomain, sOU
sUser = "admin"
sPassword = "ichdarfdas"
sDomain = "MyDomain"
sOU = "OU Path"
sCmpName = InputBox("Enter the new computer name:", "Computer Name")
If sCmpName = "" Then
Wscript.Echo "Exiting script."
Wscript.Quit
End If
Dim oWMI, oCmp, oOS, sReturn
Set oWMI = GetObject("winmgmts:\\.\root\cimv2")
For Each oCmp in oWMI.InstancesOf("Win32_ComputerSystem")
sReturn = oCmp.Rename(sCmpName)
If sReturn <> 0 Then
Wscript.Echo "Rename failed. Error = " & Err.Number & _
vbcrlf & "Exiting script."
Else
Wscript.Echo "Rename successful."
sReturn = oCmp.JoinDomainOrWorkgroup(sDomain, sPassword, _
sDomain & "\" & sUser, sOU, JOIN_DOMAIN)
If sReturn <> 0 Then
Wscript.Echo "Join domain failed. Error = " & Err.Number & _
vbcrlf & "Exiting script."
Else
Wscript.Echo "Join domain successful."
End If
Wscript.Echo "Rebooting computer..."
Dim oShell
<Script2>
Const JOIN_DOMAIN = 1
Const ACCT_CREATE = 2
Const ACCT_DELETE = 4
Const WIN9X_UPGRADE = 16
Const DOMAIN_JOIN_IF_JOINED = 32
Const JOIN_UNSECURE = 64
Const MACHINE_PASSWORD_PASSED = 128
Const DEFERRED_SPN_SET = 256
Const INSTALL_INVOCATION = 262144
Dim message
Dim IP
'Change domain, username and password here
strDomain = "domain.com"
strUser = "Admin"
strPassword = "ichdarfdas"
Set objNetwork = CreateObject("WScript.Network")
strComputer = objNetwork.ComputerName
Set objWMIService = GetObject ("winmgmts:" & "!\" & strComputer & "rootcimv2")
Set colAdapters = objWMIService.ExecQuery ("Select * from Win32_NetworkAdapterConfiguration Where IPEnabled = True")
title = "Join computer to domain"
message = "Please enter computer name. Leave blank or press cancel to quit." & vbCrLf & vbCrLf & "Generated name: " & generatedName
newComputerName = InputBox(message, title)
If newComputerName = "" Then
Wscript.quit
End If
areYousure = MsgBox("Are you sure you want t0 add computer to domain with name:" & vbCrLf & vbCrLf & newComputerName, vbYesNo + vbQuestion,"Add computer to domain")
If areYouSure = "7" Then
MsgBox "Exiting script.",vbInformation
Wscript.quit
End If
Set objComputer = GetObject("winmgmts:{impersonationLevel=Impersonate}!\" & _
strComputer & "rootcimv2:Win32_ComputerSystem.Name='" & _
strComputer & "'")
'Change OU here (Default is "OU=Computers,DC=domain,DC=com")
ReturnValue = objComputer.JoinDomainOrWorkGroup(strDomain, strPassword, strDomain & "" & strUser, "OU=My Computers,OU=Computers,DC=domain,DC=com", _
JOIN_DOMAIN + ACCT_CREATE)
If ReturnValue = 0 Then
MsgBox "Computer added to domain under old name without error. proceeding to change computer name. "
Else
MsgBox "Computer not added to domain successfully. Return value: " & ReturnValue
End If
strComputer = "."
Set objWMIService = GetObject("winmgmts:" _
& "{impersonationLevel=impersonate}!\" & strComputer & "rootcimv2")
Set colComputers = objWMIService.ExecQuery _
("Select * from Win32_ComputerSystem")
For Each objComputer in colComputers
MsgBox "About to rename computer to: " & newComputername
ErrCode = objComputer.Rename(newComputerName, strPassword, strUser)
If ErrCode = 0 Then
MsgBox "Computer renamed correctly."
Else
MsgBox "Eror changing computer name. Error code: " & ErrCode
End If
Next
Wer kann helfen - ich bin absoluter Laie - und komme nicht zurecht -
Vielen Dank an die Hilfen (aber bitte so das es ein Dau versteht - Danke!)
ich bin der absolute Laie in VB und bräuchte dringend Hilfe
Hallo Zusammen,
ich habe im Internet 2 Scripts gefunden um meine Win7 Rechner umzubenennen und und in meine Domäne zu heben. Beide Scripte werfen verschiedene Fehler aus - Fehler 0 usw Fehler.... in dem anderen Script.
Wer kann mir dabei helfen ?
Hier die Scripts:
<Script1>
Const JOIN_DOMAIN = 1
Const ACCT_CREATE = 2
Dim sCmpName
Dim sUser, sPassword, sDomain, sOU
sUser = "admin"
sPassword = "ichdarfdas"
sDomain = "MyDomain"
sOU = "OU Path"
sCmpName = InputBox("Enter the new computer name:", "Computer Name")
If sCmpName = "" Then
Wscript.Echo "Exiting script."
Wscript.Quit
End If
Dim oWMI, oCmp, oOS, sReturn
Set oWMI = GetObject("winmgmts:\\.\root\cimv2")
For Each oCmp in oWMI.InstancesOf("Win32_ComputerSystem")
sReturn = oCmp.Rename(sCmpName)
If sReturn <> 0 Then
Wscript.Echo "Rename failed. Error = " & Err.Number & _
vbcrlf & "Exiting script."
Else
Wscript.Echo "Rename successful."
sReturn = oCmp.JoinDomainOrWorkgroup(sDomain, sPassword, _
sDomain & "\" & sUser, sOU, JOIN_DOMAIN)
If sReturn <> 0 Then
Wscript.Echo "Join domain failed. Error = " & Err.Number & _
vbcrlf & "Exiting script."
Else
Wscript.Echo "Join domain successful."
End If
Wscript.Echo "Rebooting computer..."
Dim oShell
- Hier kommt der Fehler 0 PC kann nicht in domäne gehoben werden *
<Script2>
Const JOIN_DOMAIN = 1
Const ACCT_CREATE = 2
Const ACCT_DELETE = 4
Const WIN9X_UPGRADE = 16
Const DOMAIN_JOIN_IF_JOINED = 32
Const JOIN_UNSECURE = 64
Const MACHINE_PASSWORD_PASSED = 128
Const DEFERRED_SPN_SET = 256
Const INSTALL_INVOCATION = 262144
Dim message
Dim IP
'Change domain, username and password here
strDomain = "domain.com"
strUser = "Admin"
strPassword = "ichdarfdas"
Set objNetwork = CreateObject("WScript.Network")
strComputer = objNetwork.ComputerName
Set objWMIService = GetObject ("winmgmts:" & "!\" & strComputer & "rootcimv2")
Set colAdapters = objWMIService.ExecQuery ("Select * from Win32_NetworkAdapterConfiguration Where IPEnabled = True")
title = "Join computer to domain"
message = "Please enter computer name. Leave blank or press cancel to quit." & vbCrLf & vbCrLf & "Generated name: " & generatedName
newComputerName = InputBox(message, title)
If newComputerName = "" Then
Wscript.quit
End If
areYousure = MsgBox("Are you sure you want t0 add computer to domain with name:" & vbCrLf & vbCrLf & newComputerName, vbYesNo + vbQuestion,"Add computer to domain")
If areYouSure = "7" Then
MsgBox "Exiting script.",vbInformation
Wscript.quit
End If
Set objComputer = GetObject("winmgmts:{impersonationLevel=Impersonate}!\" & _
strComputer & "rootcimv2:Win32_ComputerSystem.Name='" & _
strComputer & "'")
'Change OU here (Default is "OU=Computers,DC=domain,DC=com")
ReturnValue = objComputer.JoinDomainOrWorkGroup(strDomain, strPassword, strDomain & "" & strUser, "OU=My Computers,OU=Computers,DC=domain,DC=com", _
JOIN_DOMAIN + ACCT_CREATE)
If ReturnValue = 0 Then
MsgBox "Computer added to domain under old name without error. proceeding to change computer name. "
Else
MsgBox "Computer not added to domain successfully. Return value: " & ReturnValue
End If
strComputer = "."
Set objWMIService = GetObject("winmgmts:" _
& "{impersonationLevel=impersonate}!\" & strComputer & "rootcimv2")
Set colComputers = objWMIService.ExecQuery _
("Select * from Win32_ComputerSystem")
For Each objComputer in colComputers
MsgBox "About to rename computer to: " & newComputername
ErrCode = objComputer.Rename(newComputerName, strPassword, strUser)
If ErrCode = 0 Then
MsgBox "Computer renamed correctly."
Else
MsgBox "Eror changing computer name. Error code: " & ErrCode
End If
Next
- Hier kommt Fehler in Zeile 21 usw. (weiter ging das Script nicht!*
Wer kann helfen - ich bin absoluter Laie - und komme nicht zurecht -
Vielen Dank an die Hilfen (aber bitte so das es ein Dau versteht - Danke!)
Bitte markiere auch die Kommentare, die zur Lösung des Beitrags beigetragen haben
Content-ID: 194786
Url: https://administrator.de/contentid/194786
Ausgedruckt am: 26.11.2024 um 12:11 Uhr