Solved

VBScript Permission Denied when copying files.

Posted on 2007-04-09
17
508 Views
Last Modified: 2012-06-21
Hey all,
Need some help with this script.  The script is below.  I would like to use this script to copy 4 files from a server onto any host pc that I type in the input box.  Files will copy to \\PCNAME\C$\Windows\System32.
I am getting 'Permission Denied'.  I can copy it manually, so I know I do have access.  Here is the script.

________________________________________________
Option Explicit

Dim input, strdestination, copyfiles, excopy, WshShell, sUser, sPass
sUser = "Domain\TESTUSER" 'this name has admin rights to directories
sPass = "PassWord"
Input = InputBox("Enter Name of Remote Computer")
strDestination ="\\" & Input & "\C$\Windows\System32"
set wshshell = CreateObject("Wscript.Shell")
WshShell.Run"runas /user:" & sUser & " " & CHR(34) & Input & CHR(34), 2, TRUE
WshShell.SendKeys sPass

Set EXCOPY = CreateObject("Scripting.FileSystemObject")
Set CopyFiles = EXCOPY.GetFile("L:\Wall_Street_Bull.jpg") 'will copy 4 files
CopyFiles.Copy(strDestination)



WSCript.Echo "Done"
Wscript.Quit
________________________________________________________
Thanks in advance.
0
Comment
Question by:jsctechy
  • 9
  • 8
17 Comments
 
LVL 67

Expert Comment

by:sirbounty
ID: 18877911
I would change this to:

strDestination ="\\" & Input & "\admin$\System32"

just to shorten it up a bit...and just in case system root isn't c:\windows...

What if you use this version?

Option Explicit
Dim input, strdestination, copyfiles, excopy, WshShell, sUser, sPass
sUser = "Domain\TESTUSER" 'this name has admin rights to directories
sPass = InputBox("Enter the passWord")
Input = InputBox("Enter Name of Remote Computer")
strDestination ="\\" & Input & "\admin$\System32\"
set wshshell = CreateObject("Wscript.Shell")
WshShell.Run"net use \\" & Input & "\IPC$ /user:" & sUser & sPass
Set EXCOPY = CreateObject("Scripting.FileSystemObject")
EXCOPY.CopyFiles "L:\Wall_Street_Bull.jpg", strDestination
WSCript.Echo "Done"
Wscript.Quit
0
 
LVL 1

Author Comment

by:jsctechy
ID: 18877974
Hi Sir,
I tried that.  Got an error.  I just changed it to read::::
____________________________
Option Explicit
Dim input, strdestination, copyfiles, excopy, WshShell, sUser, sPass
sUser = "TestD\TestUser" 'this name has admin rights to directories
sPass = InputBox("Enter the passWord")
Input = InputBox("Enter Name of Remote Computer")
strDestination ="\\" & Input & "\admin$\System32\"
set wshshell = CreateObject("Wscript.Shell")
WshShell.Run"net use \\" & Input & "\IPC$ /user:" & sUser & sPass
Set EXCOPY = CreateObject("Scripting.FileSystemObject")
Set CopyFiles = EXCOPY.GetFile("L:\radmin\r_server.exe","L:\radmin\raddrv.dll")
CopyFiles.Copy(strDestination)
WSCript.Echo "Done"
Wscript.Quit
________________________________
It did work.  The I changed the files to get.  I am unsure how to specify multiple files to be copied.  
0
 
LVL 1

Author Comment

by:jsctechy
ID: 18878215
On Error Resume Next
Dim input, strdestination, copyfiles, excopy, WshShell, sUser, sPass, Files, File
sUser = "UserName" 'this name has admin rights to directories
sPass = InputBox("Enter the User's Password")
Input = InputBox("Enter Name of Remote Computer")
strDestination ="\\" & Input & "\admin$\System32\"
set wshshell = CreateObject("Wscript.Shell")
WshShell.Run"net use \\" & Input & "\IPC$ /user:" & sUser & sPass
Set EXCOPY = CreateObject("Scripting.FileSystemObject")

Files=Array("r_server.exe","admdll.dll","raddrv.dll","Visedll.dll")

For each File in Files
Set CopyFiles =ExCopy.GetFile("L:\Radmin\" & File)
CopyFiles.Copy(strDestination)
Next



It looks like this works.  

Now I need to get it to install a program- silently and start the service.
The file that will be needed to install was copied.  R_Server.exe /install /silence
Then I guess a -   Net Start "Remote Administrator Service"
0
 
LVL 67

Expert Comment

by:sirbounty
ID: 18878422
Oh, I see what you were trying to do - haha - thought you were only copying the one file.

So, you're running this remotely.
Are you wanting to kick it off remotely to launch the install?
0
 
LVL 1

Author Comment

by:jsctechy
ID: 18881883
This program -Remote Admin- lets me view my user's PC.  Sometimes the service stops responding or the AV (even though it is on the allow list) will remove it....  So this will copy the 4 files needed.
I now need to install the program and start the service.
0
 
LVL 67

Expert Comment

by:sirbounty
ID: 18882260
I would use psexec to do the latter...
http://www.microsoft.com/technet/sysinternals/utilities/psexec.mspx

psexec \\RemotePC r_server.exe
followed by
psexec \\RmotePC net start r_server

Or, if you have a list of computers, save this to a batch file:

for /f %%a in (C:\Computers.txt) do (
  psexec \\%%a r_server
  psexec \\%%a net start r_server
)
0
 
LVL 1

Author Comment

by:jsctechy
ID: 18882574
Hi SirBounty,
I am familiar with the tools.  I am currently using them.  How can I tie PSEXEC or PSSERVICE into the script?
Something like-
PSEXEC \\remotepc r_server.exe /install /silence
Then will need  to start service after that.
I will just need help how to call the cscript to use it... if needed.
0
 
LVL 67

Expert Comment

by:sirbounty
ID: 18882591
You already have a shell reference, so you could use:

WshShell.Run"psexec \\" & Input & " r_server.exe /install /silence"

to launch it and
WshShell.Run"psexec \\" & Input & " net start r_server.exe" 'or use psservice here...
0
Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

 
LVL 1

Author Comment

by:jsctechy
ID: 18882664
Hi Sir,
I ended up doing that.  However, the cmd window which uses PSEXC just stays open and the script never quits.
Do I need to add a line to Exit the psexec tool?
0
 
LVL 67

Expert Comment

by:sirbounty
ID: 18882714
It would probably remain open until the installation was completed.
Are you not seeing that behavior?

The other 'option' I can think of - which I would personally prefer, would be to scheduled the installation.  This would be difficult if your clients traverse different time zones, but still not impossible.

Thus, I would calcuate the time 15 minutes from 'now' and schedule a job to run locally using the system account:

InstallTime=Replace(Replace(DateAdd("n",15,time),"AM",""), "PM","")

wshShell.Run "schtasks /s \\" & Input & " /ru System /sc once /tn RmtInst /st " & InstallTime & " /tr r_server.exe"

0
 
LVL 1

Author Comment

by:jsctechy
ID: 18882787
I am actually using this line:
WshShell.Exec("psexec \\" & Input & " r_server.exe")

So I am not installing it anymore w/ this script.  I will need to load it though, just in case it is off.  So even though I am not installing it, the program window just remains open.
0
 
LVL 67

Expert Comment

by:sirbounty
ID: 18882805
I'm not sure I follow?
Does r_server install it or run it?
0
 
LVL 1

Author Comment

by:jsctechy
ID: 18882840
R_Server.exe runs it.
R_Server.exe /install /silence will install it silently.

But I ended up doing this-

______________________
On Error Resume Next
Dim input, strdestination, copyfiles, excopy, WshShell, sUser, sPass, Files, File, RadminSvc
sUser = "UserName" 'this name has admin rights to directories
sPass = InputBox("Enter the User's Password")
Input = InputBox("Enter Name of Remote Computer")
strDestination ="\\" & Input & "\admin$\System32\"
set wshshell = CreateObject("Wscript.Shell")
WshShell.Run"net use \\" & Input & "\IPC$ /user:" & sUser & sPass
Set EXCOPY = CreateObject("Scripting.FileSystemObject")
Set RadminSvc = "Remote Task Manager"

Files=Array("r_server.exe","admdll.dll","raddrv.dll","visedll.dll")

For each File in Files
Set CopyFiles =ExCopy.GetFile("L:\Radmin\" & File)
CopyFiles.Copy(strDestination)
Next

WshShell.Exec("psexec \\" & Input & " r_server.exe")
Wscript.Echo "Files Copied."
WshShell.Exec ("pskill \\" & Input & " PSEXEC")

Wscript.Quit
__________________________
0
 
LVL 67

Expert Comment

by:sirbounty
ID: 18882881
Hmm - I'm not a fan of that solution...pskill should be a 'last resort' under normal circumstances.
If it's just a quick-fix, then it'll do the job, but it could potentially crash the app as well, couldn't it?

What's the last run of r_server for?
Oh wait - you're just trying to launch it and then leave, right?
What about altering the schtasks to be a 'onstartup' or 'onlogon' task instead?
0
 
LVL 1

Author Comment

by:jsctechy
ID: 18883300
I don't want to schedule anything.  I want it to be on demand.
This is tricky.
I want to run this command -
Net Start "Remote Administrator Service"
But cannot get the " to work properly.
I am trying -  
WshShell.Exec("psexec \\" & Input & Chr(34) & "Remote Administrator Service" & Chr(34))
0
 
LVL 67

Accepted Solution

by:
sirbounty earned 500 total points
ID: 18883347
Because that outputs:

psexec \\COMPUTERNAME"Remote Administrator Service"

See the problem? :^)  You need a space after "input"
Try this:


WshShell.Exec("psexec \\" & Input & " " & Chr(34) & "Remote Administrator Service" & Chr(34))
0
 
LVL 67

Expert Comment

by:sirbounty
ID: 18883940
Thanx :^)
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Welcome, welcome!  If you are new to the series and haven't been following along, please take a brief moment to review the first three installments: Part 1 (http://www.experts-exchange.com/Programming/Languages/Visual_Basic/VB_Script/A_266-VBScri…
I met Paul Devereux (@pdevereux) today when I responded to his tweet asking “Anybody know how to automate adding files from disk to a folder in #outlook  ?”.  I replied back and told Paul that using automation, in this case scripting, to add files t…
I designed this idea while studying technology in the classroom.  This is a semester long project.  Students are asked to take photographs on a specific topic which they find meaningful, it can be a place or situation such as travel or homelessness.…
Need to grow your business through quality cloud solutions? With everything required to build a cloud platform and solution, you may feel like the distance between you and the cloud is quite long. Help is here. Spend some time learning about the Con…

932 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

9 Experts available now in Live!

Get 1:1 Help Now