Solved

VBScript Permission Denied when copying files.

Posted on 2007-04-09
17
498 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
How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

 
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

6 Surprising Benefits of Threat Intelligence

All sorts of threat intelligence is available on the web. Intelligence you can learn from, and use to anticipate and prepare for future attacks.

Join & Write a Comment

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…
This script will sweep a range of IP addresses (class c only, 255.255.255.0) and report to a log the version of office installed. What it does: 1.)      Creates log file in the directory the script is run from (if it doesn't already exist) 2.)      Sweep…
It is a freely distributed piece of software for such tasks as photo retouching, image composition and image authoring. It works on many operating systems, in many languages.
This video discusses moving either the default database or any database to a new volume.

743 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