shell - VBScript Removing a network shortcut if it exist -


i trying check see if network location shortcut in network shortcut if exist delete , make 1 called homedrive. how ever makes homedrive doesnt delete old one. old 1 registered username hense why used %username%. need deleting

thank in advance

const nethood = &h13&  set objwshshell = createobject("wscript.shell") set objshell = createobject("shell.application")   set objfolder = objshell.namespace(nethood) set objfolderitem = objfolder.self strnethood = objfolderitem.path   set shell = createobject("wscript.shell") set fso = createobject("scripting.filesystemobject")  networkpath = shell.specialfolders("nethood") shortcut = networkpath & "\%username%.lnk" if fso.fileexists(shortcut)      fso.deletefile shortcut end if  strshortcutname = "homedrive" strshortcutpath = "\\homer-2\it$\%username%"  set objshortcut = objwshshell.createshortcut _     (strnethood & "\" & strshortcutname & ".lnk") objshortcut.targetpath = strshortcutpath objshortcut.save 

this

>> set shell = createobject("wscript.shell") >> set fso = createobject("scripting.filesystemobject") >> sfspec = fso.buildpath("%home%", "tmp.txt") >> wscript.echo cstr(fso.fileexists(sfspec)), sfspec >> sfspec = shell.expandenvironmentstrings(sfspec) >> wscript.echo cstr(fso.fileexists(sfspec)), sfspec >> false %home%\tmp.txt true c:\documents , settings\eh\tmp.txt >> 

proves fso not expand environment variables automagically.

shortcut = networkpath & "\%username%.lnk" if fso.fileexists(shortcut)  

will never true. use shell.expandenvironmentstrings().


Comments

Popular posts from this blog

python - pip install -U PySide error -

arrays - C++ error: a brace-enclosed initializer is not allowed here before ‘{’ token -

cytoscape.js - How to add nodes to Dagre layout with Cytoscape -