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\LocalSecurityPolicy\security.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:

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 

Open in new window


any help would be appreciated :)
charastAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Robberbaron (robr)Commented:
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.
0
Robberbaron (robr)Commented:
the other place to try to check is the NETLOGON share on domain controller.  just to see if it is a permissions problem.
0
Lionel MMSmall Business IT ConsultantCommented:
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).
0
Introducing Cloud Class® training courses

Tech changes fast. You can learn faster. That’s why we’re bringing professional training courses to Experts Exchange. With a subscription, you can access all the Cloud Class® courses to expand your education, prep for certifications, and get top-notch instructions.

CoralonCommented:
Is it only on the 1 server?  Otherwise you'd be overwriting the destination file.

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.).  

I can think of a few ways around this..  You could use 2 scripts.. One to generate your secedit file, and another to copy it,
You could schedule it using a domain level account.

I'd also suggest you not use the C$ share.. create a different share.

Coralon
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
charastAuthor Commented:
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.

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.).  

Open in new window

it should be running the copy impersonating my ID (domain admin).
objWMIService = GetObject("winmgmts:" & "{impersonationLevel=impersonate}!\\" & strComputer & "\root\cimv2:Win32_Process")

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?
0
Robberbaron (robr)Commented:
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

      
	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
	

Open in new window


seems a lot of code for something that should be simple....
0
charastAuthor Commented:
I have this fixed I think. still testing but it looks promising.
what I had to do is split the process into two (got the idea from the creating two separate scripts idea).
first I run the SECEDIT command and write the file locally. then I run copyfile to copy it to the central repository.

strComSec1 = "secedit /export /areas user_rights /cfg C:\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 
	Set objShell = CreateObject( "WScript.Shell" )
	Set objFSO = CreateObject("Scripting.FileSystemObject")
	objFSO.CopyFile "\\" & strComputer &"\C$\security.inf", "C:\Scripts\UpdateLocalSecurityPolicy\", True

Open in new window

0
charastAuthor Commented:
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.
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
VB Script

From novice to tech pro — start learning today.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.