How can you pick up the Windows current Username

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts
  • Mango
    Indigo Rose Customer
    • Jan 2007
    • 49

    How can you pick up the Windows current Username

    Windows can display the current Username profile, by typing %username% at a command prompt. Does anyone know if APM5 can utilise this or use any other method to find the current user's name.
  • Worm
    Indigo Rose Customer
    • Jul 2002
    • 3971

    #2
    tInfo = System.GetLANInfo()
    Dialog.Message("UserName", tInfo.User)

    Comment

    • Mango
      Indigo Rose Customer
      • Jan 2007
      • 49

      #3
      Re: Windows current user

      Thanks WORM - if anyone would know it was you, and a very quick response - thank you.
      I had thought about using the GetLANinfo, but was put off that if the user was not on a LAN then it would return 'Unknown'. However, preliminary testing since your reply, seems to return the username even when I am disconnected from the network! I'll try some more tests, and once again Thanks

      Comment

      • Worm
        Indigo Rose Customer
        • Jul 2002
        • 3971

        #4
        You could also do it this way. Download and install the Run Silent Plugin from my website (its free).

        Once installed, enable it in AMS, then use this code.
        Code:
        01 [i][COLOR='#008000']-- create text for batch file[/COLOR][/i]
        02 sOut [COLOR='#FF0000']=[/COLOR] [COLOR='#800080']"echo %username% > %temp%\\username.txt"[/COLOR]
        03 
        04 [i][COLOR='#008000']--write the batch file to the temp folder[/COLOR][/i]
        05 TextFile[COLOR='#FF0000'].[/COLOR]WriteFromString[COLOR='#FF0000']([/COLOR]_TempFolder[COLOR='#FF0000'].[/COLOR][COLOR='#FF0000'].[/COLOR] [COLOR='#800080']"\\getname.bat"[/COLOR][COLOR='#FF0000'],[/COLOR] sOut[COLOR='#FF0000'],[/COLOR] false[COLOR='#FF0000'])[/COLOR] 
        06 [i][COLOR='#008000']-- execute the batch file silently (no command window)[/COLOR][/i]
        07 RunSilent[COLOR='#FF0000'].[/COLOR]Exec[COLOR='#FF0000']([/COLOR]_TempFolder[COLOR='#FF0000'].[/COLOR][COLOR='#FF0000'].[/COLOR] [COLOR='#800080']"\\getname.bat"[/COLOR][COLOR='#FF0000'],[/COLOR] [COLOR='#800080']""[/COLOR][COLOR='#FF0000'])[/COLOR] 
        08 
        09 [i][COLOR='#008000']--get the result of the batch file[/COLOR][/i]
        10 sName [COLOR='#FF0000']=[/COLOR] TextFile[COLOR='#FF0000'].[/COLOR]ReadToString[COLOR='#FF0000']([/COLOR]_TempFolder[COLOR='#FF0000'].[/COLOR][COLOR='#FF0000'].[/COLOR] [COLOR='#800080']"\\username.txt"[/COLOR][COLOR='#FF0000'])[/COLOR] 
        11 
        12 [i][COLOR='#008000']-- display username[/COLOR][/i]
        13 Dialog[COLOR='#FF0000'].[/COLOR]Message[COLOR='#FF0000']([/COLOR] [COLOR='#800080']"User Name:"[/COLOR][COLOR='#FF0000'],[/COLOR] sName[COLOR='#FF0000'])[/COLOR] 
        14 
        15 [i][COLOR='#008000']--Clean up[/COLOR][/i]
        16 File[COLOR='#FF0000'].[/COLOR]Delete[COLOR='#FF0000']([/COLOR]_TempFolder[COLOR='#FF0000'].[/COLOR][COLOR='#FF0000'].[/COLOR] [COLOR='#800080']"\\getname.bat"[/COLOR][COLOR='#FF0000'],[/COLOR] false[COLOR='#FF0000'],[/COLOR] true[COLOR='#FF0000'],[/COLOR] false[COLOR='#FF0000'],[/COLOR] [b][COLOR='#0000FF']nil[/COLOR][/b][COLOR='#FF0000'])[/COLOR] 
        17 File[COLOR='#FF0000'].[/COLOR]Delete[COLOR='#FF0000']([/COLOR]_TempFolder[COLOR='#FF0000'].[/COLOR][COLOR='#FF0000'].[/COLOR] [COLOR='#800080']"\\username.txt"[/COLOR][COLOR='#FF0000'],[/COLOR] false[COLOR='#FF0000'],[/COLOR] true[COLOR='#FF0000'],[/COLOR] false[COLOR='#FF0000'],[/COLOR] [b][COLOR='#0000FF']nil[/COLOR][/b][COLOR='#FF0000'])[/COLOR]

        code "prettified" by AMS Code Pretty

        Comment

        • Mango
          Indigo Rose Customer
          • Jan 2007
          • 49

          #5
          I like that WORM - have downloaded your Runsilent and it works a treat. Thanks. Whilst on your website also bought your Sendkeys plugin. Just waiting for the download email now. I am currently working on an App that I will need to send key presses, so that was well timed. Thanks again mate.

          Comment

          • Worm
            Indigo Rose Customer
            • Jul 2002
            • 3971

            #6
            Thanks!

            You should have received the plugin by now. Let me know if otherwise.

            Comment

            • nals
              Forum Member
              • Feb 2007
              • 206

              #7
              Worm This is not working for me, Why??

              Comment

              • Worm
                Indigo Rose Customer
                • Jul 2002
                • 3971

                #8
                If you're speaking of the plugin, then first you need to download and install it. Once its installed, you need to start/restart AMS, then choose Project -> Plugins, and enable the Run Silent plugin. If it doesn't show in the list, then you more than likely installed it to the wrong folder. Uninstall it, then reinstall reading very carefully the directions when installing.

                If you still have problems, let me know.

                Comment

                Working...
                X