Sign in to follow this  
Followers 0
Mysticalice

probably a simple problem - .VBS to create shortcuts based on %username%

6 posts in this topic

#1 ·  Posted (edited)

First off, i'm not even sure if this is the right forum to ask this question on, but i searched for "WSH help" and got a few results from this forum, so i thought it would be worth a try :shocked:

Thanks in advance for any help you can give me.

I'm trying to create a login file that will link a user's startup folder to their desktop as a shortcut. Here's what I have:


Set oWS = WScript.CreateObject("WScript.Shell")

sLinkFile = "C:Documents and Settings%username%DesktopStartup.LNK"

Set oLink = oWS.CreateShortcut(sLinkFile)

oLink.TargetPath = "C:Documents and Settings%username%Start MenuProgramsStartup"

oLink.Save



I've put the above in a text file, and saved as *whatever*.vbs
When i try to run it, I get an error message saying:
Unable to save shortcut C:Documents and Settings%username%DesktopStartup.LNK
Code: 80070003
Source: WshShortcut.Save


If I change the sLinkFile to the user's username, for example:
sLinkFile = "C:Documents and SettingsmarysmithDesktopStartup.LNK"
then it works right away when i double click on the script, and the folder, linked to the user's startup directory, is created.

Seems it doesn't like it only when i use the "%username%" in slinkfile.

What am i doing wrong?

Any help appreciated
Regards
 

Edited by Mysticalice

Share this post


Link to post
Share on other sites



Hi,

you can do it with Autoit. :)

So long,

Mega


Scripts & functions Organize Includes Let Scite organize the include files

Yahtzee The game "Yahtzee" (Kniffel, DiceLion)

LoginWrapper Secure scripts by adding a query (authentication)

_RunOnlyOnThis UDF Make sure that a script can only be executed on ... (Windows / HD / ...)

Internet-Café Server/Client Application Open CD, Start Browser, Lock remote client, etc.

MultipleFuncsWithOneHotkey Start different funcs by hitting one hotkey different times

Share this post


Link to post
Share on other sites

...

rIGHT ON THAT ONE... gREAT HELP TOO!!!

lol

8)


NEWHeader1.png

Share this post


Link to post
Share on other sites

First off, i'm not even sure if this is the right forum to ask this question on, but i searched for "WSH help" and got a few results from this forum, so i thought it would be worth a try :)

Thanks in advance for any help you can give me.

I'm trying to create a login file that will link a user's startup folder to their desktop as a shortcut. Here's what I have:

Set oWS = WScript.CreateObject("WScript.Shell")

sLinkFile = "C:\Documents and Settings\%username%\Desktop\Startup.LNK"

Set oLink = oWS.CreateShortcut(sLinkFile)

oLink.TargetPath = "C:\Documents and Settings\%username%\Start Menu\Programs\Startup\"

oLink.Save

I've put the above in a text file, and saved as *whatever*.vbs

When i try to run it, I get an error message saying:

Unable to save shortcut C:\Documents and Settings\%username%\Desktop\Startup.LNK

Code: 80070003

Source: WshShortcut.Save

If I change the sLinkFile to the user's username, for example:

sLinkFile = "C:\Documents and Settings\marysmith\Desktop\Startup.LNK"

then it works right away when i double click on the script, and the folder, linked to the user's startup directory, is created.

Seems it doesn't like it only when i use the "%username%" in slinkfile.

What am i doing wrong?

Any help appreciated

Regards

~Lorenzo

Hi,

Just for a little trouble shooting :

Open a dos windows and type:

echo %username%

Does it give the username name?

If not double check ths system environment variables

Cheers


Old Scriptology

Visual Ping 1.8 - Mass Ping Program with export to txt delimited.

Desktop 2 RGB and YMCK - Pick a color in the desktop and get the RGB and YMCK code.

Desktop 2 RGB - Pick a color in the desktop and get the RGB code.

ShootIT 1.0 - Screen Capture full and partial screen

[font="'Arial Black';"]Remember Remember The Fifth of November.[/font]

Share this post


Link to post
Share on other sites

#5 ·  Posted (edited)

set WshShell = WScript.CreateObject("WScript.Shell")
WScript.Echo "UseName is " & WshShell.ExpandEnvironmentStrings("%username%")

In VBScript, you need to expand environmental strings. :)

Edited by MHz

Share this post


Link to post
Share on other sites

set WshShell = WScript.CreateObject("WScript.Shell")
WScript.Echo "UseName is " & WshShell.ExpandEnvironmentStrings("%username%")

In VBScript, you need to expand environmental strings. :)

Ohhhhh

Damn VBS :D

Thats why i love autoit... hehehehe :D

Cheers


Old Scriptology

Visual Ping 1.8 - Mass Ping Program with export to txt delimited.

Desktop 2 RGB and YMCK - Pick a color in the desktop and get the RGB and YMCK code.

Desktop 2 RGB - Pick a color in the desktop and get the RGB code.

ShootIT 1.0 - Screen Capture full and partial screen

[font="'Arial Black';"]Remember Remember The Fifth of November.[/font]

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!


Register a new account

Sign in

Already have an account? Sign in here.


Sign In Now
Sign in to follow this  
Followers 0