Skip to main content

Obtaining user details

Hi,
I have been trying to find a way to get the user details to pre-load a dialogbox with a possible path - eg C:\Users\jdgoodchild\Documents\IDEA9\Exports.ILB
Using set userprofile at a DOS prompt, I get USERPROFILE=C:\Users\jdgoodchild - just what I want. So I tried
Sub Main
Dim wshShell
Dim wshSystemEnv
Dim WScript
 
Set wshShell = CreateObject( "WScript.Shell" )
Set wshSystemEnv = wshShell.Environment( "PROCESS" )
''WScript.Echo "SYSTEM:  USERPROFILE=" & wshSystemEnv( "USERPROFILE" )
MsgBox wshSystemEnv("USERPROFILE") 
End Sub
 
Running gives - Error on line 9 - Application defined or object defined error
(Line 9 is MsgBox wshSystemEnv("USERPROFILE") )
Any thoughts please. Thanks, John.

Brian Element Thu, 11/12/2015 - 14:38

Hi John,

This seems to work for me:

Sub Main
 Dim objShell As Object
 Set objShell = CreateObject("WScript.Shell")
  userProfilePath = objShell.ExpandEnvironmentStrings("%UserProfile%")
  MsgBox userProfilePath
 Set objShell = Nothing
End Sub

Let me know if it is what you are looking for.

Thanks

Brian

JohnGoodchild Thu, 11/12/2015 - 20:15

Thanks Brian, that was exactly what I was looking for!
Also thank you for the time you put in to making this site such a valuable resource.
John

gabriel Mon, 03/22/2021 - 14:27

Hi i am trying to make this may you guide what is the correct way:
 
 
Sub Main
 
Call des_saldo
End Sub
 
 
 
Function des_saldo
 
Dim usuario As String
usuario ="gchandler"
 
Set db = Client.OpenDatabase("SEMIF_9.IMD")
Set task = db.ExportDatabase
task.IncludeAllFields
eqn = "VALIDACION_DIAS_MORA_AUDIT <> ""OK"""
task.PerformTask "C:\Users\"   "&usuario&"    "\Banco Internacional de Costa Rica, S.A\Gestión de Auditoría Interna - Auditoria Interna-Seguimiento\Auditoria_Continua\REPORTES\01-PRESTAMOS ESPECIFICOS Y LINEAS\Desviaciones Días Mora.XLS", "Database", "XLS8", 1, db.Count, eqn
Set db = Nothing
Set task = Nothing
End Function

Brian Element Mon, 03/22/2021 - 15:53

In reply to by gabriel

I think you have too many quotes around the variable, this might work:

task.PerformTask "C:\Users\" & usuario & "\Banco Internacional de Costa Rica, S.A\Gestión de Auditoría Interna - Auditoria Interna-Seguimiento\Auditoria_Continua\REPORTES\01-PRESTAMOS ESPECIFICOS Y LINEAS\Desviaciones Días Mora.XLS", "Database", "XLS8", 1, db.Count, eqn

Also make sure you have spaces around the & and the variable.

Also you have XLS8 where I think it should be XLSX.

Try this out and see if it works.

You can also try it manually and then go to the history to look for the proper syntax if you haven't already.

Good luck.