windows - how to make my scripts portable vbs -


this noob question..but want make scripts more portable. lets say, have coded .vbs(or script in code of nature) in usb. want run vbs on current machine. usb assigned in f: drive

however when unplugged usb , sticked machine..it going no longer f:..but e: g: or whatever

i wanted know how overcome without changing directly on scripts script capable of reading directory pointing toward.

im not sure how property/functionality called.

but appreciate hints/tips

there 2 main ways can make script more portable.

the first, , appropriate use case, check drive executable running on using wscript.scriptfullname , getting first 3 characters find drive letter. alternatively chop script name (wscript.scriptname) off end find current working directory. assign variable, , use everywhere in code specify path.

dim fullname : fullname = wscript.scriptfullname dim drive : drive = mid(fullname, 1, 3) dim path : path = mid(fullname, 1, len(fullname) - len(wscript.scriptname)) wscript.echo "drive = " & drive & vbcrlf & "path = " & path 

another way make script expect run-time arguments user, can specify want things.

' make shortcut script , add parameter, ' or run command prompt additional parameter. if wscript.arguments.length = 0     wscript.echo "no arguments supplied!"     wscript.quit end if  wscript.echo wscript.arguments(0) 

i hope helps!


Comments

Popular posts from this blog

sequelize.js - Sequelize group by with association includes id -

android - Robolectric "INTERNET permission is required" -

java - Android raising EPERM (Operation not permitted) when attempting to send UDP packet after network connection -