Hi all. I have been messing about with a couple of scripts to make a shortcut on my desktop. I have been using xxmklink.exe and this works pretty well. Though I would like to learn how to do it via .vbs. I have this .cmd Code: @echo off %system% xxmklink.exe %USERPROFILE%\Desktop\Documents.lnk %USERPROFILE%\Documents > nul Using the %USERPROFILE% allows me to add this into my $OEM$ and run via runonce Works a treat. I know how to make a .vbs to make a shortcut with this script Code: Option Explicit Dim obj, nLink Set obj = CreateObject("wscript.shell") Set nLink = obj.CreateShortcut("C:\Users\Malc's\Desktop\Documents.lnk") nLink.TargetPath = "C:\Users\Malc's\Documents" nLink.Description = "My Documents" nLink.IconLocation = "C:\windows\MyIcons.dll,6" nLink.Save As you can see I have to write the path using the systems name. Trouble is I don't always install onto a PC called "Malc's" I also have this script Code: Set objShell = CreateObject("Wscript.Shell") strProfile = objShell.ExpandEnvironmentStrings("%userprofile%") Wscript.Echo strProfile which displays the current user. What I would like to do is make my .vbs script use %userprofile% instead of an actual name. Know what I mean ? Spent the last hour or so getting very frustrated trying to learn how to write a script. kept getting errors. so Please help.
@tnx Hope this is what you're looking for: Code: Option Explicit Dim objShell, strProfile, strWinDir, nLink Set objShell = CreateObject("Wscript.Shell") strProfile = objShell.ExpandEnvironmentStrings("%userprofile%") strWinDir = objShell.ExpandEnvironmentStrings("%windir%") Set nLink = objShell.CreateShortcut(strProfile & "\Desktop\Documents.lnk") nLink.TargetPath = strProfile & "\Documents" nLink.Description = "My Documents" nLink.IconLocation = strWinDir & "\MyIcons.dll,6" nLink.Save Your whole problem was just string concatenation i guess, which is done using the ampersand char '&'. Tell me the results. EDIT: also here's a detailed list of environment variables: http://ss64.com/nt/syntax-variables.html
I think you need to retrieve it like so: Code: usrProfile = WshS.ExpandEnvironmentStrings("%UserProfile%")
Just got in from work, coffee time then sleep. Thanks for the replies guys, can't wait to test this out later. Will report back later on..
That .vbs is beautifull. Amended it to create two desktop shortcuts. Code: Option Explicit Dim objShell, strProfile, strWinDir, nLink , nLink2 Set objShell = CreateObject("Wscript.Shell") strProfile = objShell.ExpandEnvironmentStrings("%userprofile%") strWinDir = objShell.ExpandEnvironmentStrings("%windir%") Set nLink = objShell.CreateShortcut(strProfile & "\Desktop\Documents.lnk") Set nLink2 = objShell.CreateShortcut(strProfile & "\Desktop\Pictures.lnk") nLink.TargetPath = strProfile & "\Documents" nLink.workingdirectory = strProfile & "\Documents" nLink.Description = "My Documents" nLink.WindowStyle = 3 nLink.IconLocation = strWinDir & "\MyIcons.dll,1" nLink.Save nLink2.TargetPath = strProfile & "\Pictures" nLink2.workingdirectory = strProfile & "\Pictures" nLink2.Description = "My Pictures" nLink2.WindowStyle = 3 nLink.IconLocation = strWinDir & "\MyIcons.dll,2" nLink2.Save Worked really well. So I guess expanding it to create as many shortcuts as I wish is possible. @wk-952
Thought I would edit it a little further, give the nLink a bit more meaning. Code: Option Explicit Dim objShell, strProfile, strWinDir, Desktop , Pictures Set objShell = CreateObject("Wscript.Shell") strProfile = objShell.ExpandEnvironmentStrings("%userprofile%") strWinDir = objShell.ExpandEnvironmentStrings("%windir%") Set Desktop = objShell.CreateShortcut(strProfile & "\Desktop\Documents.lnk") Set Pictures = objShell.CreateShortcut(strProfile & "\Desktop\Pictures.lnk") Desktop.TargetPath = strProfile & "\Documents" Desktop.workingdirectory = strProfile & "\Documents" Desktop.Description = "My Documents" Desktop.WindowStyle = 3 Desktop.IconLocation = strWinDir & "\MyIcons.dll,1" Desktop.Save Pictures.TargetPath = strProfile & "\Pictures" Pictures.workingdirectory = strProfile & "\Pictures" Pictures.Description = "My Pictures" Pictures.WindowStyle = 3 Desktop.IconLocation = strWinDir & "\MyIcons.dll,2" Pictures.Save works really well. Just gunna add this to my OOBE script via runonce and test the results.
Just tested it and it worked quite well. The shortcuts did appear on my desktop at first boot but I made a small error and the pictures shortcut icon was not right. Code: Option Explicit Dim objShell, strProfile, strWinDir, Desktop , Pictures Set objShell = CreateObject("Wscript.Shell") strProfile = objShell.ExpandEnvironmentStrings("%userprofile%") strWinDir = objShell.ExpandEnvironmentStrings("%windir%") Set Desktop = objShell.CreateShortcut(strProfile & "\Desktop\Documents.lnk") Set Pictures = objShell.CreateShortcut(strProfile & "\Desktop\Pictures.lnk") Desktop.TargetPath = strProfile & "\Documents" Desktop.workingdirectory = strProfile & "\Documents" Desktop.Description = "My Documents" Desktop.WindowStyle = 3 Desktop.IconLocation = strWinDir & "\MyIcons.dll,1" Desktop.Save Pictures.TargetPath = strProfile & "\Pictures" Pictures.workingdirectory = strProfile & "\Pictures" Pictures.Description = "My Pictures" Pictures.WindowStyle = 3 Desktop.IconLocation = strWinDir & "\MyIcons.dll,2" Pictures.Save tut tut tut...
@wk-952 I am going to have a go at making a folder via .vbs using "%userprofile%. If I get stuck and I probably will. Can you help me out please ?
Well i'm a complete beginner in VB scripts, i'm honestly only interested in batch, so you should probably ask someone of more knowledge than me. But if it's something i know, i will surely help you immediately, but again don't expect much from me in VB scripts. My apologies if i disappointed you.
Took me a while but I got it... Rather pleased with myself. Code: Option Explicit Dim objShell, fso, APPsFolder Set objShell = WScript.CreateObject("Wscript.Shell") Set fso = CreateObject("Scripting.FileSystemObject") APPsFolder = objShell.ExpandEnvironmentStrings("%userprofile%") fso.CreateFolder(APPsFolder & "\APPs")
Editing a bit further to make my desired folder and create a shortcut for that folder in "SendTo" Works like a charm.. Code: Option Explicit Dim objShell, fso, APPsFolder, APPsShortcut, MyIconDLLFile Set objShell = WScript.CreateObject("Wscript.Shell") Set fso = CreateObject("Scripting.FileSystemObject") APPsFolder = objShell.ExpandEnvironmentStrings("%userprofile%") MyIconDLLFile = objShell.ExpandEnvironmentStrings("%SystemRoot%") fso.CreateFolder(APPsFolder & "\APPs") Set APPsShortcut = objShell.CreateShortcut(APPsFolder & "\AppData\Roaming\Microsoft\Windows\SendTo\APPs.lnk") APPsShortcut.workingdirectory = APPsFolder & "\APPs" APPsShortcut.TargetPath = APPsFolder & "\APPs" APPsShortcut.Description = "APPs Folder Shortcut" APPsShortcut.WindowStyle = 3 APPsShortcut.IconLocation = MyIconDLLFile & "\MyIcons.dll,6" APPsShortcut.Save