Announcement

Collapse
No announcement yet.

Startup/Logoff/Shutdown Script

Collapse
X
  • Filter
  • Time
  • Show
Clear All
new posts

  • Startup/Logoff/Shutdown Script

    Hello,
    I have a logon script that runs a command (see below) that writes data to a log file on a share on our server. I want it to write similar data to a different log file when the computer starts up, logs off and shuts down. I was told to add runas but I don't know where to add it or how. Any suggestions?

    echo %date% - %time% - %computername% - %username% - Logon Successful >> \\SERVER-01\Apps01$\logs\Logon\logfile.log

  • #2
    Re: Startup/Logoff/Shutdown Script

    You can use group policy and run it at logon and logoff, and i think it runs under the system account so doesnt need any runas.
    Please remember to award reputation points if you have received good advice.
    I do tend to think 'outside the box' so others may not always share the same views.

    MCITP -W7,
    MCSA+Messaging, CCENT, ICND2 slowly getting around to.

    Comment


    • #3
      Re: Startup/Logoff/Shutdown Script

      Originally posted by uk_network View Post
      You can use group policy and run it at logon and logoff, and i think it runs under the system account so doesnt need any runas.
      I do use group policy but for some reason they do not write to the log. Only the logon works.

      Comment


      • #4
        Re: Startup/Logoff/Shutdown Script

        The startup scripts will be running as a local admin on the PCs so won't automatically have access to network resources, I can only assume that is why you were told to use run as.

        Your script should work for log on / log off

        For help with the runas command just open a command prompt and type runas. Stick you command line in quotes and supply it as the "program" for runas and specify a domain user that has access to the network share.

        The problem with that is the password for runas must be entered interactively and thus the script wouldn't run properly. You may even find your PC hanging waiting for a response that you can't input because you just have a screen saying "Running startup scripts"

        You could have the startup script do:

        Code:
        net use \\SERVER-01\Apps01$ t: /user:DOMAIN\user password
        your command >> t:\logs\startup\logfile.log 	
        net use t: /delete
        I'm not sure if mapped drives will work at that stage though and you will need to use a very basic user account that has access to nothing but the log share. Anyone who can access that batch file will get that password so you don't want expose anything you don't have to.

        A more secure method may be to have the startup script write a local log file and the login script copy the local log file to a network respository.

        We implemented this kind of solution to monitor a terminal server, however we didn't do startup scripts. I do however have a vbs script at the office that allows you to send an email instead of write a logfile so that may even be preferable. Let me know and I can dig it out.

        Comment


        • #5
          Re: Startup/Logoff/Shutdown Script

          you could try doing it \\server\share and sharing out the directory thats its trying to write too, opening it wide open for testing, the account it uses could have some permission issue writing to
          \\SERVER-01\Apps01$\logs\Logon\logfile.log


          also another option would be to have it write the log file like this:

          %date% - %time% - %computername% - %username% - Logon Successful >> \\SERVER-01\Logon\%computername%_%username%.log
          Please remember to award reputation points if you have received good advice.
          I do tend to think 'outside the box' so others may not always share the same views.

          MCITP -W7,
          MCSA+Messaging, CCENT, ICND2 slowly getting around to.

          Comment


          • #6
            Re: Startup/Logoff/Shutdown Script

            Originally posted by beddo View Post
            The startup scripts will be running as a local admin on the PCs so won't automatically have access to network resources, I can only assume that is why you were told to use run as.
            Although Startup scripts and shutdown scripts run under the Local system, it can access the network in its domain. On the client both the 'Network Service' and 'Local System' accounts can access the network acting as the machine. It is using NTLM or Kerberos for authentication.

            By default the primary group for all computers in a domain is 'Domain Computers'. Also like users in a domain the computers are automatically member of 'Authenticated Users' too.

            If the startup script did not write to the log-file, first confirm the script actually did run, then check the share and ntfs permissions on the file and folder. The group 'Authenticated Users' or else the group 'Domain Computers' must at least have Modify permissions over there.

            Mapped drives will not work.

            /Rems
            Last edited by Rems; 26th May 2011, 11:32.

            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

            Comment


            • #7
              Re: Startup/Logoff/Shutdown Script

              Originally posted by Rems View Post
              Although Startup scripts and shutdown scripts run under the Local system, it can access the network in its domain. On the client both the 'Network Service' and 'Local System' accounts can access the network acting as the machine. It is using NTLM or Kerberos for authentication.

              By default the primary group for all computers in a domain is 'Domain Computers'. Also like users in a domain the computers are automatically member of 'Authenticated Users' too.

              If the startup script did not write to the log-file, first confirm the script actually did run, then check the share and ntfs permissions on the file and folder. The group 'Authenticated Users' or else the group 'Domain Computers' must at least have Modify permissions over there.

              Mapped drives will not work.

              /Rems

              This fixed my problem! I added Domain Computers to the share and gave it modify permissioin. All scripts work. Thank you! I didn't want to add Authenticated Users because then all users (people) have the ability to go in and alter the logs.

              Comment

              Working...
              X