charast
asked on
run a command line command on a remote target with VBscript
I need to run SECEDIT /export on a remote machine and copy the resulting file to a central location using VBscript and WMI.
I basically have the code to run a remote command ( i have used this before successfully) but this instance is giving me fits since I am trying to copy the result to a central location via UNC.
I am trying to run the following command:
secedit /export /areas user_rights /cfg \\servername\c$\scripts\Lo calSecurit yPolicy\se curity.inf
if i run that command locally on the target server it works fine and copies the resulting file. but in the script it fails to copy the file over. intProcessID does return a processID so i assume the base command is working just not the copy part. I am sure I am missing something small like quotes or something...
here is a snippet of the code I am using:
any help would be appreciated :)
I basically have the code to run a remote command ( i have used this before successfully) but this instance is giving me fits since I am trying to copy the result to a central location via UNC.
I am trying to run the following command:
secedit /export /areas user_rights /cfg \\servername\c$\scripts\Lo
if i run that command locally on the target server it works fine and copies the resulting file. but in the script it fails to copy the file over. intProcessID does return a processID so i assume the base command is working just not the copy part. I am sure I am missing something small like quotes or something...
here is a snippet of the code I am using:
strComSec1 = "secedit /export /areas user_rights /cfg \\servername\c$\scripts\LocalSecurityPolicy\security.inf"
Set objWMIService = GetObject("winmgmts:" & "{impersonationLevel=impersonate}!\\" & strComputer & "\root\cimv2:Win32_Process")
errReturn = objWMIService.Create(strComSec1,Null,Null,intProcessID)
if errReturn = 0 Then
Wscript.Echo "Command was started with a process ID of: " & intProcessID
objLogfile.writeline "Command was started with a process ID of: " & intProcessID
Else
Wscript.Echo "command did not run. Error: " & errReturn
objLogfile.writeline "command did not run. Error: " & errReturn
End If
any help would be appreciated :)
what happens if you create a new share on the 'central' server, rather than trying to use the admin C$ one. give the share full access to Everyone.
the other place to try to check is the NETLOGON share on domain controller. just to see if it is a permissions problem.
I believe the the problem is the $ in the UNC. try putting the entire unc in " " or you may have to surround it with ^$^ (but try quotes first as I am not all confident about the second suggestion); otherwise creating a share is a quick and easy solution; using the admin share is not a "good practice" (I have been told).
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
ok. I got back to this issue this morning...
I tried some of the suggestions but it still is not working. I created a share, everyone full for the share perms and everyone full for the NTFS. it still wont copy the file.
I tried putting the UNC path in quotes. it still wont copy the file.
I have not tried 2 different scripts. I really dont want to have to do that but I will look into it.
objWMIService = GetObject("winmgmts:" & "{impersonationLevel=imper sonate}!\\ " & strComputer & "\root\cimv2:Win32_Process ")
any other suggestions?
I tried some of the suggestions but it still is not working. I created a share, everyone full for the share perms and everyone full for the NTFS. it still wont copy the file.
I tried putting the UNC path in quotes. it still wont copy the file.
I have not tried 2 different scripts. I really dont want to have to do that but I will look into it.
How are you running it on that server? If you are using one of the builtin accounts, it may not have access to the network, which would cause the copy to fail. (i.e. the service account, the local administrator account etc.).
it should be running the copy impersonating my ID (domain admin). objWMIService = GetObject("winmgmts:" & "{impersonationLevel=imper
Is it only on the 1 server? Otherwise you'd be overwriting the destination file.It will be more than one server. I am not worried about the "overwriting" as I have that covered with other code later on that is not shown above.
any other suggestions?
only other option may be to map the central share to a drive letter temporariy...
try this , potentially by itself to just test the logging portion
seems a lot of code for something that should be simple....
try this , potentially by itself to just test the logging portion
Arc_Dest="V:\" 'base for storage
'connect to the arc_dest using special permissions
Dim strUser, strPassword, strDriveLetter, strHomeServer, strProfile
Dim objNetwork, objPopUp
Set objNetwork = CreateObject("WScript.Network")
Set objPopUp = CreateObject("WScript.Shell")
strDriveLetter = left(Arc_dest,2) '"V:"
strProfile = "False" ' Mapping (not) stored in user Profile
strUser = "archive_admin"
strPassword = "SomePassw0rd"
objNetwork.MapNetworkDrive strDriveLetter, Arc_Destpath, strProfile, strUser, strPassword
'--------------------------
cmdrun=true
If UCase(Right(Wscript.FullName, 11)) = "WSCRIPT.EXE" Then
cmdrun=false
End if
MoreProject = true
Dim objFSO: Set objFSO = CreateObject("Scripting.FileSystemObject")
if not objFSO.FileExists(arc_list) Then
Wscript.Echo "Input file not found"
Wscript.Quit
end if
Dim objFile: Set objFile = objFSO.OpenTextFile(arc_list)
Dim RawString, arclistdata
sLogFile = Arc_list & ".LOG"
'setup logging
if objFSO.FileExists(sLogFile) Then
set oLogFile = objFSO.OpenTextFile (sLogFile,8) 'append
else
Set oLogFile = objFSO.CreateTextFile(sLogFile,true,false)
end if
oLogFile.WriteLine "----Begin--- " & Date & "," & Time
seems a lot of code for something that should be simple....
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
using the suggestion of two scripts, I expanded on that an re-wrote the code myself to split the create/copy process into two distinct steps.