I have an ini file that I'm using. In it are 2 lines, a SMB link to an application and a hostname identifier.
This is what the app.ini file looks like:
FilePath=\\server\application.exe
Hostname = Computer
I want to use a VB script to take the username of the person who’s logged in and replace ‘computer’ with that user’s domain username. This way I don't have to edit every single app.ini
This is my script, when I double click it, it runs fine but it doesn’t replace the hostname with my username
' --- Global Declarations ---
Dim oWshShell
Dim ofso
Dim file
Dim sStartupCommand
Dim oWshNetwork
dim sLoginName
Dim sUserIniLocation
Dim sUserIniFile
Dim sBaseIniFile
Dim sHostname
Dim oParmFile
dim strParmFileText
dim sReplaceText
'
Set ofso = CreateObject("Scripting.FileSystemObject")
Set oWshShell = CreateObject("Wscript.Shell")
Set oWshNetwork = CreateObject("Wscript.Network")
SHostname = Environ("Username")
sUserIniLocation = "C:\localfolder\txt\"
sUserIniFile = sUserIniLocation & "app.ini"
sReplaceText = "Hostname=computer"
set oParmFile = oFSO.openTextFile(sUserIniFile)
strParmFileText = oParmFile.readall
oParmFile.close
strParmFileText = replace(strParmFileText, sReplaceText, SHostname)
set oParmFile = oFSO.openTextFile(sUserIniFile,2)
oParmFile.write(strParmFileText)
oParmFile.close
Open in new window
with thisOpen in new window
then change this line:
Open in new window