Link to home
Start Free TrialLog in
Avatar of iamuser
iamuser

asked on

VB Script and getting domain username

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
Avatar of sirbounty
sirbounty
Flag of United States of America image

Try replacing
SHostname = Environ("Username")

Open in new window

with
Set objSysInfo = CreateObject("ADSystemInfo")
sHostname = objSysInfo.UserName

Open in new window

Avatar of iamuser
iamuser

ASKER

I will give that a try
Avatar of iamuser

ASKER

it worked but it replaced the entire "hostname=computer" line with a "CN, DC" line

I like to replace only the 'computer' portion of that line
ASKER CERTIFIED SOLUTION
Avatar of sirbounty
sirbounty
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of iamuser

ASKER

Let me try that, thanks for the help
SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of iamuser

ASKER

Will re-post again since this is so old