Please Read: Significant Update Planned, Migrating Forum Software This Month

See more
See less

Psexec/bat credentials question

  • Filter
  • Time
  • Show
Clear All
new posts

  • Psexec/bat credentials question


    I am having a problem using psexec to deploy a bat script. The issue is that the psexec must be run with my admin credentials, however the script accesses a %username%$ share which must be run under local credentials.

    I thought that perhaps using:

    psexec @C:\computers.txt -u ADMIN -c C:\cmd1.cmd

    wherein cmd1 is a simple:
    pushd \\share\folder
    call cmd2.cmd

    However, that does not seem to work. Any suggestions? Any way to utilize the user credentials?

  • #2
    Re: Psexec/bat credentials question

    What is the nature of the failure? Post the results or symptoms.

    VCDX3 #34, VCDX4, VCDX5, VCAP4-DCA #14, VCAP4-DCD #35, VCAP5-DCD, VCPx4, vEXPERTx4, MCSEx3, MCSAx2, MCP, CCAx2, A+ - VMware Virtualization Evangelist
    My advice has no warranties. Follow at your own risk.


    • #3
      Re: Psexec/bat credentials question

      The nature of the failure:

      1. running cmd2 file without admin == Access denied.

      2. Running cmd2 with admin == script runs fine, but cannot access the %username%$ share as it is on the parent domain and only users are permissioned. The script runs to completion but does not successfully finish that task (robocopy)


      • #4
        Re: Psexec/bat credentials question

        A member of the 'Domain Admins' should have permission to access the share server\<username>$ as wel as any folder on the local computer. (?right?)

        I think the problem here are the variables in the user's session environment.

        If the script is runned by an other account, it wil not run in the environment of te account that is currently logged on to the console. It is not aware of that account. The variable %username% that is used in your batch will be translated to the remote administratoraccount, or the local systemaccount or All Users - but never the name of that user sitting behind the computer.
        Therefore you cannot use the variable %username% in that script.

        To get the correct sharename now, you have to determine the name of the current user account first, and create a special variable %currentusername% that can be used in the batch.

        You can determine the name of the user by using a vbscript.
        The script can run your batch with the name of the user as a parameter.
        In your batch add this line: SET %currentusername% = %1
        Now use the %currentusername% variable instead of the %username%

        Here you can find an example of a vbscript that can determine the username remotely. (in your case you don't need the SID of the user so the script can be shortened a bit)

        Last edited by Rems; 20th April 2007, 22:33.

        This posting is provided "AS IS" with no warranties, and confers no rights.


        ** Remember to give credit where credit's due **
        and leave Reputation Points for meaningful posts


        • #5
          Re: Psexec/bat credentials question

          That was a great post, thank you- some very good stuff to look at. I, however, was less than clear.

          The issue is not actually failing on a %username% variable. Our logon script maps this drive to the U drive, and it is actually referenced in the script as such. Basically, the only way the script starts with psexec is under admin credentials. Admin credentials do not have access to the U drive, and so the script does not run properly. Is there anyway to pass the local credentials so that I can still deploy with psexec but the script runs properly?

          edit: attempting to use unc paths with correct variables does not work as psexec still runs under my credentials. Still cannot access the username shares
          Last edited by damnlamb; 24th April 2007, 21:52. Reason: i am smart