Results 1 to 2 of 2

Thread: Bat file for logon script

  1. #1
    Join Date
    May 2010

    Bat file for logon script

    I wrote a simple batch file that only writes an eventlog with message: SessionID = %SessionName%.

    I want to run the script for users (which aren't connected to the domain) everytime they logon.
    I don't want to restart the machine to run the script. (So I cannot just put the script in the "start folder".

    I have some problems:

    0. Is there a way to set that via c# code?

    1. How do I assign this script to be every user logon script? I read many ways to do so but none worked for me (premission mainly).

    2. Sometimes when I run the batch file locally and manually - the "SessionName" variable doesn't appear in the environment variables. but only sometimes. What could be the reason ?

    3. Now I run rdp.exe via c# to open new sessions. I have also tried to run Psexec with -i flag (attached to a specific session) but SessionName was missing again... Any ideas?

    4. Another solution I have thought of:
    execute it remotely using Psexec --> cmd --->batch file (withut the cmd "in the middle" the SessionName doesn't appear).

    so I have tried
    c:\PsTools\psexec.exe \\<Server> -u test2 -p <Password> -i 2 cmd "c:\Users\test-2\Desktop\a"

    c:\PsTools\psexec.exe \\<server> -u test2 -p <Password> -i 2 "cmd \"c:\Users\test-2\Desktop\a\""

    all of these just open a terminal on the remote machine but don't execute the batch.

  2. #2
    Join Date
    Mar 2009

    Re: Bat file for logon script

    Actually it depends on what server you are using still here you have the steps to create a login script.
    • Navigate to the folder where scripts are held on primary domain controller.
    • As you can only have one login script edit the existing text file.
    • Add the lines of instructions and then save it as a batch file.
    • Assign the script to the computers that need to run it. This is usually done by means of the user profile of the person who normally logs in to that workstation.
    Last edited by ZeDaX; 10-05-2010 at 11:45 AM.

Similar Threads

  1. Replies: 3
    Last Post: 17-08-2010, 09:06 PM
  2. Run logon script
    By Sandy22 in forum Operating Systems
    Replies: 6
    Last Post: 08-06-2010, 10:16 AM
  3. Logon Script Does Not Work
    By c54618 in forum Operating Systems
    Replies: 1
    Last Post: 01-05-2008, 08:40 AM
  4. domain logon script does not run
    By Onetoomany in forum Windows Server Help
    Replies: 4
    Last Post: 11-02-2008, 04:37 AM
  5. logon script help
    By HandelMan in forum Small Business Server
    Replies: 1
    Last Post: 31-01-2008, 02:26 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts