I have a vbsscript that I can deploy to users that will create a shortcut to an FTP drive on the user's desktop. This script works in this form:
Set objShell=Wscript.CreateObject("Wscript.shell")
strDesktopFolder=objShell.SpecialFolders("Desktop") & "\"
Set objShortcut=objShell.CreateShortcut(strDesktopFolder & "FTP.lnk")
objShortCut.TargetPath = "ftp://ftp.website.com"
objShortCut.Description = "FTP"
objShortCut.Save
This is great, but it requires that the user type a username and password to access the folder. I really need to save the username and password before as part of the deployment and eliminate extra steps for the end-user. Therefore, I want to save the username and password as part of the vbs script when I deploy it. I have come close and can save a username and password with the following:
Set objShell=Wscript.CreateObject("Wscript.shell")
strDesktopFolder=objShell.SpecialFolders("Desktop") & "\"
Set objShortcut=objShell.CreateShortcut(strDesktopFolder & "FTP.lnk")
objShortCut.TargetPath = "ftp://user:pass#ftp.website.com"
objShortCut.Description = "FTP"
objShortCut.Save
However, the issue is that I can't save them correctly. The username format is:
user#website.com
This is the format for my ftp site. I cannot change that. This format returns an error (800A0005). I need my script to work without error like this:
Set objShell=Wscript.CreateObject("Wscript.shell")
strDesktopFolder=objShell.SpecialFolders("Desktop") & "\"
Set objShortcut=objShell.CreateShortcut(strDesktopFolder & "FTP.lnk")
objShortCut.TargetPath = "ftp://user#website.com:pass#ftp.website.com"
objShortCut.Description = "FTP"
objShortCut.Save
Thanks for any and all help!
If your username contains the # symbol, and your web browser or the windows explorer does not like it, you must substitute it with the + symbol like this :
user#website.com = user+website.com
Set objShell=Wscript.CreateObject("Wscript.shell")
strDesktopFolder=objShell.SpecialFolders("Desktop") & "\"
Set objShortcut=objShell.CreateShortcut(strDesktopFolder & "FTP.lnk")
objShortCut.TargetPath = "ftp://user+website.com:pass#ftp.website.com"
objShortCut.Description = "FTP"
objShortCut.Save
Related
This question already has answers here:
can you get the pc user name in vbs?
(2 answers)
Closed 4 years ago.
I need to find a way to get the current user of the system and put it in the address.
Right now I am using this script:
Set WshShell = CreateObject("WScript.Shell")
Dim User
User = "User"
WshShell.Run Chr(34) & "C:\Users\" & User & "\Documents\Test\M2.bat" & Chr(34), 0
Set WshShell = Nothing
I am using it to run a batch file without showing. Right now to change the user I have to change the variable myself. Is there a way to make it automatic?
Msgbox CreateObject("WScript.Shell").SpecialFolders("MyDocuments")
The correct way is to ask the system where is My Documents. Users can move them.
There are several ways of obtaining the username of the currently logged-in user, for example:
expanding the environment variable %USERNAME%:
Set sh = CreateObject("WScript.Shell")
User = sh.ExpandEnvironmentStrings("%USERNAME%")
via the UserName property of a WshNetwork object:
Set net = CreateObject("WScript.Network")
User = net.UserName
from the Win32_ComputerSystem WMI class:
Set wmi = GetObject("winmgmts://./root/cimv2")
For o In wmi.ExecQuery("SELECT * FROM Win32_ComputerSystem")
User = o.UserName
Next
via ADSI:
Set sys = CreateObject("ADSystemInfo")
User = sys.UserName
For a more complete list see this overview compiled by Rob van der Woude.
I've created a VBScript to run a macro from excel without opening the file.
Set objExcel = CreateObject("Excel.Application")
objExcel.Application.Run "'C:\Users\MyUser\Desktop\RM.xlsm'!Module4.Email"
objExcel.DisplayAlerts = False
objExcel.Application.Quit
Set objExcel = Nothing
I want to use this VBScript & XLSM file on different computers, so how can i change this script to work without editing the path every time?
(Maybe a code to run from current folder or a code to run from any user desktop)
If the file will always be on the desktop of every user then you can use environment variables to determine the location.
Set wshShell = CreateObject( "WScript.Shell" )
userName = wshShell.ExpandEnvironmentStrings( "%UserName%" )
path = "'C:\Users\" + userName + "\Desktop\RM.xlsm'!Module4.Email"
Set objExcel = CreateObject("Excel.Application")
objExcel.Application.Run path
objExcel.DisplayAlerts = False
objExcel.Application.Quit
Set objExcel = Nothing
(Untested code)
If the file is not on each user's desktop then you'll need to store it in a common location on the network and have each user access it from there, e.g. in .
\\YourFileSever\SharedFiles\RM.xlsm
In practical terms the latter is preferable as it means the workbook is in only one place and when it comes to releasing a new version you only have to update one copy
I have a network share already setup. I am trying to create a VBScript that will create a folder in the share called computername, which is the PC's name. The script will run locally on the PC, access the share and create the folder in the share.
My error is "bad path". I'm guessing I can't just state the network share path?
My script is below:
Dim objShell
Set oWS = WScript.CreateObject("WScript.Shell")
Set objShell = Wscript.CreateObject("WScript.Shell")
Set objFSO = CreateObject("Scripting.FileSystemObject")
computername = oWS.ExpandEnvironmentStrings( "%COMPUTERNAME%" )
If NOT (objFSO.FolderExists("\\ServerPath\Share$" + computername)) Then
objFSO.CreateFolder("\\ServerPath\Share$" + computername)
End If
You're lacking a backslash between the name of the share and the name of the folder you want to create. Also, I'd recommend using a variable for the path, so you don't have to construct it multiple times.
Change this:
If NOT (objFSO.FolderExists("\\ServerPath\Share$" + computername)) Then
objFSO.CreateFolder("\\ServerPath\Share$" + computername)
End If
into this:
path = "\\ServerPath\Share$\" & computername
If NOT objFSO.FolderExists(path) Then
objFSO.CreateFolder(path)
End If
Need assistance in creating vbs. I have exe which can be executed from anywhere. so i need to get the exe location and add to registry entry.
Ex: location of exe : c:\abc\execute.exe
registry location : HKEY_CURRENT_USER\Software\Microsoft\Windows NT\CurrentVersion\AppCompatFlags\Compatibility Assistant\Persisted
Add key as c:\abc\execute.exe dword=1
thanks in advance
You could use something like this, if I am understanding your question correctly.
To call this script, you would simply go to the Start menu, and type into the search box (or run box):
cscript {path-to-your-script\scriptname.vbs} /filepath:"C:\abc\execute.exe"
You would need to replace {path-to-your-script\scriptname.vbs} with the full path and filename of the script example provided below. Remember to save the code snippet with a .vbs extension.
This vbs snippet will silently add C:\abc\execute.exe with a dword value of 1 under the key HKEY_CURRENT_USER\Software\Microsoft\Windows NT\CurrentVersion\AppCompatFlags\Compatibility Assistant\Persisted if the registry path exists and the executing account has sufficient permissions to do so.
NOTE: This script snippet will not work on older versions of Windows as wscript.arguments.Named.Item is not supported.
' cscript <scriptname.vbs> /filepath:"C:\abc\execute.exe"
Const HKEY_CURRENT_USER = &H80000001
filePath = wscript.arguments.Named.Item("filepath")
Value = 1
strComputer = "."
Set objRegistry = GetObject("winmgmts:\\" & strComputer & "\root\default:StdRegProv")
strKeyPath = "Software\Microsoft\Windows NT\CurrentVersion\AppCompatFlags\Compatibility Assistant\Persisted"
if filePath <> "" then
objRegistry.SetDWORDValue HKEY_CURRENT_USER, strKeyPath, filepath, Value
end if
Hope that helps.
I have created a VBScript which pulls the service tag, username, and computer name from a computer. What I need to do now is compile this information in a text document.
How it's set up is as follows:
We have an Active Directory Server, with a folder for login scripts. I have created a batch file to run this .vbs script, and the script works well so far. What I now need is for a file on the AD server, called "logging.txt", to be populated with the information that is created with the .vbs script.
This is the script I have so far:
'Get Dell Service Tag Info
set ProSet = GetObject("winmgmts:").InstancesOf("Win32_BIOS")
Set ProSet1 = GetObject("winmgmts:").InstancesOf("Win32_SystemEnclosure")
For each Pro in ProSet
For each Pro1 in ProSet1
ServiceTag=Pro.SerialNumber
wscript.echo ServiceTag
exit for
Next
exit for
Next
'get username and computername, could also be asked in a batch
Set oShell = WScript.CreateObject("WScript.Shell")
Set oShellEnv = oShell.Environment("Process")
sComputerName = oShellEnv("ComputerName")
sUsername = oShellEnv("username")
wscript.echo sComputerName & " " & sUsername
Thank you very much in advance!
This is what I've tried so far:
sub log (user, computer)
dim fs,f
set fs=Server.CreateObject("Scripting.FileSystemObject")
set f=fs.OpenTextFile(Server.MapPath(".\logging.csv"),8,true)
f.WriteLine now & "," & user & "," & computer
f.Close:set f=Nothing
set fs=Nothing
end sub
I feel as though you're leaving something out.. this is how to write a text file in VBS.
dim filesys, filetxt, getname, path
Set filesys = CreateObject("Scripting.FileSystemObject")
Set filetxt = filesys.CreateTextFile("c:\somefile.txt", True)
path = filesys.GetAbsolutePathName("c:\somefile.txt")
getname = filesys.GetFileName(path)
filetxt.WriteLine("Your text goes here.")
filetxt.Close
If filesys.FileExists(path) Then
Response.Write ("Your file, '" & getname & "', has been created.")
End If
It would probably be easiest to save the information to a local text file and upload it with the command line ftp utility from the batch script that calls your script rather than trying to invent another wheel and do it in vbscript.
You can list the command line options of ftp with:
ftp /?
I recommend setting up something like this:
ftp -s:control.txt
control.txt would contain something like:
open [hostname or address]
[username]
[password]
cd [remote directory name]
put logging.txt
disconnect
bye