From: PeterP on
I want to do an install onto another computer over the network - this script
is throwing up an eror saying I don't have permissions to access the IP
specified in the script.

I am therefore wanting to connect as the network admin, or local admin of
that PC - how do I do this??

So far it is bumming out here

Set oSvcRemote = GetObject("winmgmts:\\" & ip & "\root\cimv2", _
admin_user, admin_user_password)

don't know if this is the correct way to do it??

Cheers ears

___________________________________

admin_user = "domain\someone"
admin_user_password = "something"

'ipFile = path to list of hosts
ipFile = "C:\scripts\installmsas\list.txt"

'execPath = path to executable file
execPath = "C:\scripts\installmsas\msantispy.msi"

'execCommand = command to execute, including path, switches, etc
execCommand = "msiexec.exe /i c:\msantispy.msi /qn INSTALLDIR=c:\MSAS\"
execCommand2 = "C:\msas\gcasDtServ.exe /regserver"

'fileName = filename of executable
fileName = "msantispy.msi"

'pathToLog = path to the logfile
pathToLog = "C:\scripts\installmsas\install_log.txt"

On Error Resume Next
Set oNet = CreateObject("WScript.Network")
Set oFS = CreateObject("Scripting.FileSystemObject")
Set oSvcLocal = GetObject("winmgmts:root\cimv2")
Set oIPFile = oFS.OpenTextFile(ipFile, 1, false)
Set oOutputFile = oFS.CreateTextFile(pathToLog, TRUE)


If (Err.Number <> 0) Then
WScript.Echo "Cannot open " & ipFile
WScript.Quit
End If


While Not oIPFile.atEndOfStream
ip = oipFile.ReadLine()
oOutputFile.WriteLine(vbCrLf & "Connecting to " & ip & "... ")
WScript.Echo vbCrLf & "Connecting to " & ip & "... "

Err.Clear
Set oSvcRemote = GetObject("winmgmts:\\" & ip & "\root\cimv2", _
admin_user, admin_user_password)

If (Err.Number <> 0) Then
oOutputFile.WriteLine("Failed to connect to " & ip & "." & vbCrlf
& Err.Number & " - " & Err.Description)
WScript.Echo "Failed to connect to " & ip & "." & vbCrlf & Err.Number
& " - " & Err.Description
Else
oNet.RemoveNetworkDrive "J:"
oNet.MapNetworkDrive "J:", "\\" & ip & "\C$"

' copy msas file to remote pc
Set oSourceFile = oSvcLocal.Get("cim_datafile=""" & replace(execPath,
"\", "\\") & """")
returnCode = oSourceFile.Copy("J:\\" & fileName)

If (returnCode <> 0 and returnCode <> 10) Then
' Failure detected and failure was not "file already exists."
oOutputFile.WriteLine("Failed copy " & fileName & " to " & ip & " - Error
Code: " & returnCode)
WScript.Echo "Failed copy " & fileName & " to " & ip & " - Error Code: "
& returnCode
oNet.RemoveNetworkDrive "J:"
Else
oOutputFile.WriteLine(fileName & " copied to " & ip)
WScript.Echo fileName & " copied to " & ip
Set oProcess = oSvcRemote.Get("win32_process")
returnCode = oProcess.Create(replace(execCommand, "\",
"\\"))
If (returnCode <> 0) Then
oOutputFile.WriteLine("Failed to start install on "
& ip & " Error Code: " & returnCode)
WScript.Echo "Failed to start install on " & ip & "
Error Code: " & returnCode
oNet.RemoveNetworkDrive "J:"
Else
Set oDestFile = oSvcLocal.Get("cim_datafile=""J:\\"
& fileName & """")
'Wait for the installation to complete.
For waitTime = 0 To 120 ' Lay and wait--up to
two minutes for the installation to complete.
WScript.Sleep 10000 ' Sleep
'Delete temporary file as soon as possible
after it is freed.
If (oDestFile.Delete() = 0) Then
Exit For
End If
Next ' Otherwise, loop again and keep waiting...
oOutputFile.WriteLine("Installation successful on
" & ip & ".")
WScript.Echo "Installation successful on " & ip &
"."

End If 'Create process succeeded.

'now register server
returnCode = oProcess.Create(replace(execCommand2, "\", "\\"))
If (returnCode <> 0) Then
oOutputFile.WriteLine("Failed to register server on
" & ip & " Error Code: " & returnCode)
WScript.Echo "Failed to register server on " & ip &
" Error Code: " & returnCode
Else
oOutputFile.WriteLine("Registration successful on "
& ip & ".")
WScript.Echo "Registration successful on " & ip &
"."
End If
End If
End If
WEnd
oOutputFile.Close



From: "Michael Harris (MVP)" <mikhar at mvps dot on
PeterP wrote:
> I want to do an install onto another computer over the network - this
> script is throwing up an eror saying I don't have permissions to
> access the IP specified in the script.
>
> I am therefore wanting to connect as the network admin, or local
> admin of that PC - how do I do this??
>
> So far it is bumming out here
>
> Set oSvcRemote = GetObject("winmgmts:\\" & ip & "\root\cimv2", _
> admin_user, admin_user_password)
>
> don't know if this is the correct way to do it??


SWbemLocator.ConnectServer (9 Parameters) method [WMI]
http://msdn.microsoft.com/library/en-us/wmisdk/wmi/swbemlocator_connectserver.asp?frame=true

Connecting to WMI on a Remote Computer [WMI]
http://msdn.microsoft.com/library/en-us/wmisdk/wmi/connecting_to_wmi_on_a_remote_computer.asp?frame=true

Google Search
http://groups-beta.google.com/groups?q=connectserver%20group:*.scripting

Google Search: connectserver site:microsoft.com/technet
http://www.google.com/search?q=connectserver%20site:microsoft.com/technet&num=100&scoring=d

--
Michael Harris
Microsoft MVP Scripting
-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
Please ask follow-up questions via the original newsgroup thread.