VBScript Permission Denied when copying files.

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.
LVL 1
jsctechyAsked:
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.

sirbountyCommented:
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
jsctechyAuthor Commented:
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
jsctechyAuthor Commented:
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
Cloud Class® Course: CompTIA Cloud+

The CompTIA Cloud+ Basic training course will teach you about cloud concepts and models, data storage, networking, and network infrastructure.

sirbountyCommented:
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
jsctechyAuthor Commented:
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
sirbountyCommented:
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
jsctechyAuthor Commented:
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
sirbountyCommented:
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
jsctechyAuthor Commented:
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
sirbountyCommented:
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
jsctechyAuthor Commented:
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
sirbountyCommented:
I'm not sure I follow?
Does r_server install it or run it?
0
jsctechyAuthor Commented:
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
sirbountyCommented:
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
jsctechyAuthor Commented:
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
sirbountyCommented:
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

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
sirbountyCommented:
Thanx :^)
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.