0

I've written the script below but when I run it (using PrimalScript for troubleshooting) I get the error 'Permission denied'. I'm admin on this device and I get the same error when I run the script elevated.

Here is the script:

Dim WshShell, strCurDir, File, strDesktop

Set WshShell = CreateObject("WScript.Shell")
strDesktop = WshShell.SpecialFolders("AllUsersDesktop")
Set ofso = CreateObject("Scripting.FileSystemObject")
strPath = ofso.GetParentFolderName(WScript.ScriptFullName)
File = "pwsafe.psafe3"
strCurDir = ofso.BuildPath(strPath, File)

ofso.CopyFile strCurDir , strDesktop , OverwriteExisting

What am I doing wrong?

Ansgar Wiechers
  • 193,178
  • 25
  • 254
  • 328

2 Answers2

0

You must set a process:

Dim ofso, oshell, oproc, strDesktop, overwrite
Set ofso = CreateObject("Scripting.FileSystemObject")
Set oshell = CreateObject("WScript.Shell")
Set oproc  = oshell.Environment("Process")
strDesktop = oproc.Item("UserProfile") & "\Desktop\"
overwrite = True
ofso.CopyFile "pwsafe.psafe3" , strDesktop , overwrite
user692942
  • 16,398
  • 7
  • 76
  • 175
  • As you can see, I'm nothing but a script kiddie but don't have much time to learn. However, the Dim in your solution had the comma missing. Once I put it into place, it worked like a charm. Thank you. – totalyscrewedup Sep 21 '15 at 14:26
  • Is that the All Users profile? Shouldn't it be `strDesktop = oproc.Item("ALLUSERSPROFILE") & "\Desktop\"`? – user692942 Sep 21 '15 at 15:59
  • You didn't need to change the OPs code that much, all they needed is `Set oproc = oshell.Environment("Process")` they could then use `strDesktop = oproc.Item("AllUsersDesktop")` no problem. – user692942 Sep 21 '15 at 16:07
  • @totalyscrewedup You do realise that isn't the All Users Desktop which is what you asked for? – user692942 Sep 21 '15 at 16:09
  • While Sergio's script worked great locally, during testing via primalScript, it failed with permissions issue when ran via platform. Since the platform deployment normally creates the shortcuts via vbs just fine, I was confused why I'm getting access denied error. So, the statement that it won't write to 'allusersdesktop' is correct. I tried Lankymart's suggestions and utilized the suggested change to my original script to look like this but it failes with 'Invalid proceedure call or argument': – totalyscrewedup Sep 21 '15 at 17:17
  • Dim oproc, strCurDir, File, strDesktop, oshell Set oshell = CreateObject("WScript.Shell") Set oproc = oshell.Environment("Process") strDesktop = oproc.Item("AllUsersDesktop") Set ofso = CreateObject("Scripting.FileSystemObject") strPath = ofso.GetParentFolderName(WScript.ScriptFullName) File = "pwsafe.psafe3" strCurDir = ofso.BuildPath(strPath, File) ofso.CopyFile strCurDir , strDesktop , OverwriteExisting – totalyscrewedup Sep 21 '15 at 17:19
0

while my last comment showed the script that doesn't work, the script below is combination of Sergio's and Lankymart's work. Wanted to mention them both since they deserve the credit. Here is the working script and I hope someone else makes use of it.

Dim ofso, oshell, oproc, strDesktop, overwrite
Set ofso = CreateObject("Scripting.FileSystemObject")
Set oshell = CreateObject("WScript.Shell")
Set oproc  = oshell.Environment("Process")
strDesktop = oproc.Item("ALLUSERSPROFILE") & "\Desktop\"
overwrite = True
ofso.CopyFile "pwsafe.psafe3" , strDesktop , overwrite

Thank you both.

  • Since both have contributed, I can't pick one over the other. If another noob like me goes through it, they need to know the correct code, without having to guessing what code is working. – totalyscrewedup Feb 07 '17 at 16:33