LotusScript: Obtendo as variáveis de ambiente do Windows

From Wiki
Revision as of 11:51, 30 October 2008 by Ebasso (talk | contribs)

Uma pergunta comum em Windows é como obter o usuário atual do sistema, o nome da máquina, etc ...

O código abaixo faz isso

Sub Initialize

   Dim wshShell As Variant
   Dim strUser As String
   Dim strComputer As String
   Dim strServer As String 
   Dim strUserDomain As String 
	
   Set wshShell = CreateObject("WScript.Shell")
   strUser = wshShell.ExpandEnvironmentStrings("%USERNAME%")
   Print "User [" + strUser + "]"
   
   strComputer = wshShell.ExpandEnvironmentStrings("%COMPUTERNAME%")
   Print "Computer [" +strComputer + "]"
 	
   strServer = wshShell.ExpandEnvironmentStrings("%LOGONSERVER%")
   Print "logonServer [" + strServer + "]"
 
   strUserDomain = wshShell.ExpandEnvironmentStrings("%USERDOMAIN%")
   Print "strUserDomain [" + strUserDomain + "]"
End Sub