Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chris Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Permission denied

Status
Not open for further replies.

dniskin

Programmer
Jun 23, 2007
7
GB
This is my code, but it says on line 16 char 1 permission is denied:

Const HIDDEN_WINDOW = 12
strComputer = "ADMIN-PC"
Set objWMIService = GetObject("winmgmts:" _
& "{impersonationLevel=impersonate}!\\" & strComputer & "\root\cimv2")
Set objStartup = objWMIService.Get("Win32_ProcessStartup")
Set objConfig = objStartup.SpawnInstance_
objConfig.ShowWindow = HIDDEN_WINDOW
Set objProcess = GetObject("winmgmts:root\cimv2:Win32_Process")
errReturn = objProcess.Create _
("cmd /K cd C:\Program Files\ & md NetMessage", null, objConfig, intProcessID)

Const OverwriteExisting = TRUE

Set objFSO = CreateObject("Scripting.FileSystemObject")

objFSO.CopyFile "\\ADMIN-PC\C$\Program Files\receiver.exe", "\\ADMIN-PC\C$\Program

Files\NetMessage", OverWriteExisting

strComputer = "ADMIN-PC"
Set objWMIService = GetObject("winmgmts:" _
& "{impersonationLevel=impersonate}!\\" & strComputer & "\root\cimv2")
Set objStartup = objWMIService.Get("Win32_ProcessStartup")
Set objConfig = objStartup.SpawnInstance_
objConfig.ShowWindow = HIDDEN_WINDOW
Set objProcess = GetObject("winmgmts:root\cimv2:Win32_Process")
errReturn = objProcess.Create _
("cmd /K cd C:\Program Files\NetMessage & receiver.exe", null, objConfig, intProcessID)

Any ideas?
 
Replace this:
("cmd /K cd C:\Program Files\ & md NetMessage", null, objConfig, intProcessID)
with this:
("cmd /K cd ""C:\Program Files\"" & md NetMessage", null, objConfig, intProcessID)

Hope This Helps, PH.
FAQ219-2884
FAQ181-2886
 
Sorry didn't help, the problem is with the objFSO.CopyFile line. Thanks anyway.
 
Sorry didn't help
Your original code didn't raise any error on that line ?
Anyway, what about this:
objFSO.CopyFile "\\ADMIN-PC\C$\Program Files\receiver.exe", "\\ADMIN-PC\C$\Program Files\NetMessage\receiver.exe", OverWriteExisting

Hope This Helps, PH.
FAQ219-2884
FAQ181-2886
 
In fact, you had a problem at least here:
objFSO.CopyFile "\\ADMIN-PC\C$\Program Files\receiver.exe", "\\ADMIN-PC\C$\Program Files\NetMessage[highlight][!]\[/!][/highlight]", OverWriteExisting

Hope This Helps, PH.
FAQ219-2884
FAQ181-2886
 
Thanks for your help, but sadly it's still not working.
 
You obviously have necessary credentials on ADMIN-PC ?
What happens if you do the same thing manually ?

Hope This Helps, PH.
FAQ219-2884
FAQ181-2886
 
It works manually, yes I have the necessary credentials. Should I making 3 scripts instead of 1 i.e split it up?
 
What is your actual code (as I suggested 3 modifications: 2 for cmd /K and 1 for CopyFile)

BTW, \\ADMIN-PC\C$\Program Files\receiver.exe is open by no one at the time you try to copy it ?

Hope This Helps, PH.
FAQ219-2884
FAQ181-2886
 
Yes it was open I looked in processes, my script had worked once but under a hidden window, then when I tried to do it again, it came up with permission denied and has done since. Thanks for your help.
 
Just to know, did you apply the 3 modifications I suggested you ?
 
Yes, one of them was not helpful, this was the one concerning changing the path of my program. Thankyou.
 
So, for the benefit of other members, what is your actual working code ?
 
Const HIDDEN_WINDOW = 12
strComputer = "ADMIN-PC"
Set objWMIService = GetObject("winmgmts:" _
& "{impersonationLevel=impersonate}!\\" & strComputer & "\root\cimv2")
Set objStartup = objWMIService.Get("Win32_ProcessStartup")
Set objConfig = objStartup.SpawnInstance_
objConfig.ShowWindow = HIDDEN_WINDOW
Set objProcess = GetObject("winmgmts:root\cimv2:Win32_Process")
errReturn = objProcess.Create _
("cmd /K cd C:\Program Files\ & md NetMessage & exit", null, objConfig, intProcessID)

Const OverwriteExisting = TRUE

Set objFSO = CreateObject("Scripting.FileSystemObject")

objFSO.CopyFile "C:\Program Files\NetMessage\receiver.exe", "\\ADMIN-PC\C$\Program Files\NetMessage\", OverWriteExisting

strComputer = "ADMIN-PC"
Set objWMIService = GetObject("winmgmts:" _
& "{impersonationLevel=impersonate}!\\" & strComputer & "\root\cimv2")
Set objStartup = objWMIService.Get("Win32_ProcessStartup")
Set objConfig = objStartup.SpawnInstance_
Set objProcess = GetObject("winmgmts:root\cimv2:Win32_Process")
errReturn = objProcess.Create _
("cmd /K cd C:\Program Files\NetMessage & receiver.exe", null, objConfig, intProcessID)
 
try to get out of the habit of binding to WMI root and classes etc over and over again in your scripts, it is not required and the more often you bind the slower your scripts become
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top