Try using double quotes i.e. ""%windir%......LockWorkSt
Main Topics
Browse All TopicsI am trying to create a script that will automatically create a shortcut to lock the computer. I would like the script to create the shortcut everythime the user logs on.
This is what I have that sort of works
Dim objShell, strPath
Dim objShortcut
Set objShell = CreateObject("Wscript.Shel
strPath = objShell.SpecialFolders("D
Set objShortcut = objShell.CreateShortcut(st
With objShortcut
.Targetpath = "%windir%\System32\rundll3
'''other options can be entered here
.Save
End With
Set objShortcut = Nothing
Set objShell = Nothing
It will create a shortcut on the users desktop, but the problem is that the shortcut path reads
"%windir%\System32\rundll3
when it need to read
%windir%\System32\rundll32
If I try and remove the quotes in the script i get an error.
any help would be appreciated.
PS. It doesn't have to be written in vbs, I just need it to work as a windows 2003 domain logon script
This Question has been solved and asker verified All Experts Exchange premium technology solutions are available to subscription members.
Experts Exchange has been collecting answers to technology questions since 1996…3 million and counting! If you have a question, chances are we already have your answer.
If you can't find the exact answer you're looking for, ask our exclusive community of 50,000 experts. You’ll get a personalized answer from a trusted professional.
Thousands of free tech tips, tricks, how-to’s and tutorials are available in our peer reviewed articles section. See for yourself how smart our experts are, no login required.
Access the answers to your technology questions today.
30-day free trial. Register in 60 seconds.
Members of the expert community talk about why the experience at Experts Exchange is different than what you will find anywhere else.

Try it out and discover for yourself.
30-day free trial. Register in 60 seconds.
Join the community of experts here and help other tech pros by answering question in your area of expertise. You can earn FREE access to all Experts Exchange's premium features and resources.
I used the code above for creating links on the desktop but could not get it to work. I quickly added a message to the desktop in the code to make sure the file is being accessed during logon and it works. There are no error during logon either. I double checked my network path and filename and it looks rith to me. What do you think could be wrong?
Business Accounts
Answer for Membership
by: tigermattPosted on 2007-09-08 at 14:02:43ID: 19854539
I see your problem, and have a (sort of) solution. How about create the shortcut beforehand, then use a vbs to copy if from the netlogon directory to the desktop?
pting.File SystemObje ct") ipt.Networ k") ipt.Shell" )
esktop") & "\"
path) Then
Create the Lock Computer shortcut and place it in \\<your domain name>\NETLOGON (can also be accessed via \\<servername>\NETLOGON
For the purposes of this script, the shortcut should be called Lock Computer, but the name can be changed in the script.
Copy and paste the following script and save it as a vbs file.
Option Explicit
' Copy shortcut file
' Lock Computer shortcut
' Logon script
' VBS format
dim objfso,objnetwork,objshell
dim userdomain, netlogonpath, desktoppath
Set objfso = WScript.CreateObject("Scri
Set objnetwork = WScript.CreateObject("WScr
Set objshell = WScript.CreateObject("WScr
userdomain = objnetwork.UserDomain
netlogonpath = "\\" & userdomain & "\NETLOGON\Lock Computer.lnk"
desktoppath = objshell.SpecialFolders("D
if objfso.FileExists(netlogon
objfso.CopyFile netlogonpath,desktoppath
end if
The script will automatically get the user's domain name, so you don't need to set that. Assuming you only have one active directory domain it shouldn't be a problem, otherwise just put it in the NETLOGON folder for all the domains the script will run for.
Then assign it as a logon script in a GPO as per usual. I suggest you test it first just by running the script manually though!
If you want top change the shortcut name, you'll need to update this line:
netlogonpath = "\\" & userdomain & "\NETLOGON\Lock Computer.lnk"
Change Lock Computer.lnk to <new shortcut name>.lnk and obviously make sure the shortcut matches the name exactly.
Let me know if you have any issues
tigermatt