Jump to content

sam240

Member
  • Posts

    14
  • Joined

  • Last visited

  • Donations

    0.00 USD 
  • Country

    United States

Posts posted by sam240

  1. 21 hours ago, sam240 said:

    I'm trying to figure out what is the best way to run this reg on computers just once after log on.

    The problem is my imaged computers popup "Library" window every time a user logs into windows and this registry below fixes it. I have this in a batch file but how can I run it only once on the machine after logon? I know I can use Task Scheduler but Task Scheduler doesn't give me the option to run it only once and same with group policy. 

    
    reg add "HKLM\SOFTWARE\Microsoft\Windows NT\CurrentVersion\Winlogon" /v Userinit /t REG_SZ /d "C:\Windows\system32\userinit.exe," /t

    I appreciate your help.

    Well I was able to figure it out on my own. In case someone needs it.

    I created a batch file and added it to Local C:\support\fix.bat (I created a support folder)

    To only run once,

    open regedit

     goto HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\RunOnce

    Create a new string and name it whatever you like and in DATA field, add the path to the batch file which in my case is C:\support\fix.bat and that worked like a charm. It automatically gets removed from registry after it runs so it does not run over and over again.

    @echo off
    
    SET FLAG=%TEMP%\Flag.txt
    
    IF EXIST %FLAG% GOTO END
    
    reg add "HKLM\SOFTWARE\Microsoft\Windows NT\CurrentVersion\Winlogon" /v Userinit /t REG_SZ /d "C:\Windows\system32\userinit.exe," /t > %FLAG%
    
    :END
  2. I'm trying to figure out what is the best way to run this reg on computers just once after log on.

    The problem is my imaged computers popup "Library" window every time a user logs into windows and this registry below fixes it. I have this in a batch file but how can I run it only once on the machine after logon? I know I can use Task Scheduler but Task Scheduler doesn't give me the option to run it only once and same with group policy. 

    reg add "HKLM\SOFTWARE\Microsoft\Windows NT\CurrentVersion\Winlogon" /v Userinit /t REG_SZ /d "C:\Windows\system32\userinit.exe," /t

    I appreciate your help.

  3. Hello,

    This may be very simple but for some reason it's not working for me so I thought I come here for help.

    I'm running windows 7 64-bit and all I would like to do is run 3 batch scripts which install a software.

     

    I have 4 batch files named, 1.bat, 2.bat, 3.bat, 4.bat

     

    I use bat 1 to run the other 3 batch files which install programs as some suggested to use CALL method but it does not work on windows 7.

     

    1.bat currently reads (PAUSE is so I can read the errors)

     

    Call 2.bat
    PAUSE
    Call 3.bat
    PAUSE
    CALL 4.bat
    PAUSE

     

    When I run 1.bat, I get the following errors

     

    C:\Windows>Call 2.bat
    '2.bat' is not recognized as an internal or external command,
    operable program or batch file.

    C:\Windows>PAUSE
    Press any key to continue . . .

    C:\Windows>Call 3.bat
    '3.bat' is not recognized as an internal or external command,
    operable program or batch file.

    C:\Windows>PAUSE
    Press any key to continue . . .

    C:\Windows>CALL 4.bat
    '4.bat' is not recognized as an internal or external command,
    operable program or batch file.

    C:\Windows>PAUSE
    Press any key to continue . . .

     

    what command can I use to execute these batch files probably one at a time. Any help will be appreciated.  Thank you

  4. As jaclaz mentioned I just had to remove "%" from front of delims. This seems to work but now but I think it's not recognizing %today% from the imagex line. I get the following msg from imagex

    IMG_0300.jpg

     

     

    echo off
    Title Deploying Laptop Base Image
    diskpart /s diskpartscript2.txt
    cls
    SET Today=
    FOR /F "tokens=2 delims==" %%A IN ('FIND "TheLast"^<i:\lenovo\base\blank\last.ini') DO SET Today=%%A
    IF NOT DEFINED Today ECHO ERROR...&PAUSE
    imagex /apply i:\lenovo\base\blank\%today%\image.wim W:\
    bcdboot W:\Windows /s S:
    PAUSE
    exit
     

  5. Well,

    you can have in the "deploy" batch (say):

      

    SET Today=FOR /F "tokens=2 %delims==" %A IN ('TYPE i:\lenovo\domain\blank\last.ini ^| FIND "TheLast"') DO SET Today=%%AIF NOT DEFINED Today ECHO ERROR...&PAUSE"imagex /apply i:\lenovo\domain\blank\%today%\image.wim"
    jaclaz

     

     

     

     

    Well,

    you can have in the "deploy" batch (say):

      

    FOR /F "tokens=2 %delims==" %A IN ('TYPE i:\lenovo\domain\blank\last.ini ^| FIND "TheLast"') DO SET Today=%%A
     

    and have in the "imaging" one: 

    IF NOT EXIST i:\lenovo\base\blank\%Today% MD i:\lenovo\base\blank\%Today%ECHO TheLast=%Today%>i:\lenovo\base\blank\last.ini
    jaclaz

     

     

    change to

    FOR /F "tokens=2 %delims==" %%A IN ('FIND "TheLast"^<i:\lenovo\domain\blank\last.ini') DO SET Today=%%A

    When I used the

     

    SET Today=

    FOR /F "tokens=2 %delims==" %A IN ('TYPE i:\lenovo\domain\blank\last.ini ^| FIND "TheLast"') DO SET Today=%%A

    IF NOT DEFINED Today ECHO ERROR...&PAUSE

    imagex /apply i:\lenovo\domain\blank\%today%\image.wim

     

    I got an error which says " the syntax of the command is incorrect".

    This is exactly what my script is like. Upto diskpart /s diskpartscript2.txt it works fine right after the cls, it gives me the syntax of the command is incorrect error. I tried both jaclaz's and Yzowl's

     

    I was able to capture the image and it created an last.ini in this directory i:\lenovo\base\blank\last.ini and also created a folder with the image.wim inside the folder with date.

     

     

    echo off

    Title Deploying Laptop Base Image

    diskpart /s diskpartscript2.txt

    cls

    SET Today=

    FOR /F "tokens=2 %delims==" %A IN ('TYPE i:\lenovo\base\blank\last.ini ^| FIND "TheLast"') DO SET Today=%%A

    IF NOT DEFINED Today ECHO ERROR...&PAUSE

    imagex /apply i:\lenovo\base\blank\%today%\image.wim W:\

    bcdboot W:\Windows /s S:

    PAUSE

    exit

     

     

  6. Well,

    you can have in the "deploy" batch (say):

      

    SET Today=FOR /F "tokens=2 %delims==" %A IN ('TYPE i:\lenovo\domain\blank\last.ini ^| FIND "TheLast"') DO SET Today=%%AIF NOT DEFINED Today ECHO ERROR...&PAUSE"imagex /apply i:\lenovo\domain\blank\%today%\image.wim"
     

    and have in the "imaging" one: 

    SET Today=%date:~10,4%-%date:~4,2%-%date:~7,2%IF NOT EXIST i:\lenovo\base\blank\%Today% MD i:\lenovo\base\blank\%Today%ECHO TheLast=%Today%>i:\lenovo\base\blank\last.iniimagex /compress fast /capture D: i:\lenovo\base\blank\%Today%\image.wim "Laptop Base Image"
    jaclaz

     

     

     

     

    Well,

    you can have in the "deploy" batch (say):

      

    FOR /F "tokens=2 %delims==" %A IN ('TYPE i:\lenovo\domain\blank\last.ini ^| FIND "TheLast"') DO SET Today=%%A
     

    and have in the "imaging" one: 

    IF NOT EXIST i:\lenovo\base\blank\%Today% MD i:\lenovo\base\blank\%Today%ECHO TheLast=%Today%>i:\lenovo\base\blank\last.ini
    jaclaz

     

     

    change to

    FOR /F "tokens=2 %delims==" %%A IN ('FIND "TheLast"^<i:\lenovo\domain\blank\last.ini') DO SET Today=%%A

    and

    IF NOT EXIST i:\lenovo\base\blank\%Today%\ MD i:\lenovo\base\blank\%Today%>i:\lenovo\base\blank\last.ini ECHO;TheLast=%Today%

     

     

     

    Along with jaclaz idea, a symlink could be created as well. May as well create a symlink for static path handling and use the last.ini for reference to the last date. The use of a static path can help with WAIK tools or similar and less maintenance of suggested code in other scripts that also access the image file.

     

    This code is not tested so let me know if issues exist so I can fix it. I expect it to work though I have been wrong before.

    @ECHO OFFSETLOCALrem # Set the date to a variable named Today.SET Today=%date:~10,4%-%date:~4,2%-%date:~7,2%rem # Make a folder for Today.IF NOT EXIST i:\lenovo\base\blank\%Today%\ MD i:\lenovo\base\blank\%Today%rem # Capture the image to Todays folder.imagex /compress fast /capture D: i:\lenovo\base\blank\%Today%\image.wim "Laptop Base Image"rem # Write Todays date to last.ini and symlink the image if no error detected from imagex.IF ERRORLEVEL 1 (	rem # Output the detection of an imagex error.	>&2 ECHO Error %errorlevel% set by imagex.	>&2 IF EXIST i:\lenovo\base\blank\%Today%\image.wim ECHO Image does exist in Todays directory.) ELSE (	rem # Write the last date to last.ini.	(ECHO TheLast=%Today%)>i:\lenovo\base\blank\last.ini		rem # Remove the last symlink as mklink does not overwrite.	IF EXIST i:\lenovo\base\blank\image.wim DEL i:\lenovo\base\blank\image.wim		rem # Create symlink in the blank directory to Todays image.	mklink i:\lenovo\base\blank\image.wim i:\lenovo\base\blank\%Today%\image.wim	IF ERRORLEVEL 1 >&2 ECHO Error %errorlevel% set by mklink.)ENDLOCALGOTO :EOF

    You guys are freaking genius! This made my life so much easier. Thank you so much jaclaz for the last.ini idea and thanks yzowl for tweaking it and also thank you MHZ for tweaking it. I did try jaclaz's script and that worked I haven't tried MHZ's script yet. I'll give it show tomorrow and get back to you. Each image takes a little time to capture so testing takes a while for each script.

  7.  

    The only problem with this is that I have another batch file which deploys the captured image and that script pulls from the main folder such as i:\lenovo\base\blank\image.wim so say now the new image is in %Today% folder, I'll have to manually edit the script each time or copy and paste the image outside of the %Today% folder.

     

    Not really-really.

     

    I mean there are several possibilities, one being that the batch (the one that creates the image in the %today% folder) also  creates a hard link (I presume that you are using NTFS) in the main directory or, possibly even better/easier as hardlinks are a bit more difficult to manage, use a softlink (to the file) or a junction point from the %today% directory to a "fixed" place, let's say i:\lenovo\base\blank\last\

    http://ss64.com/nt/mklink.html

    http://schinagl.priv.at/nt/hardlinkshellext/linkshellextension.html

     

    The poor man's way (or on non NTFS) would be to have the "imaging batch" write a simple plain text file, let's say  last_to_be_deployed.ini and have the "deploy batch" to parse it and get the actual value of the %today%, i.e. the folder name from which to get the image, or you could get rid of the subdirectories have all the images in i:\lenovo\base\blank\ and assign a meaningful name to the images themselves, like naming the actual image to %today%.img and have the deploying batch use last created one (which would be another advantage as you wouldn't have a zillion of files all named "image.img" and only differentiated - besides creation timestamp - only by the name of the folder in which they are).

     

    There are endless possibilities.

     

    jaclaz

     

    Thank you for your help.

     

    this is what my script looks like for deploying

    "imagex /apply i:\lenovo\domain\blank\image.wim"

     

    and to be really honest, I have no expierence in scripting which is why I'm here. I tried your script above and it worked beautifully. It created a folder with today's date and create the new image in it.

  8. Well, to be fair there is no real need for robocopy, the file is before and after on a same volume, MOVE (which will simply update the path of the file should be robust enough, or if you prefer in the given scenario there is not actually any "data transfer".

     

    But, even before that, it is the procedure that in itself can be simplified.

     

    The base assumption is that the "last previous" image is created in a "nameless folder", i.e. "I:\lenovo\base\blank" and when the batch is run the pre-existing image in the "nameless" folder is moved to a new, "named after date" subfolder, and then a new image is created in the same "nameless" folder.

     

    Wouldn't it be easier to simply create the image (also the "first" one) directly in a ""named after date" subfolder?

    I.e. all in all, something *like* :

    SET Today=%date:~10,4%-%date:~4,2%-%date:~7,2%IF NOT EXIST i:\lenovo\base\blank\%Today% MD i:\lenovo\base\blank\%Today%imagex /compress fast /capture D: i:\lenovo\base\blank\%Today%\image.wim "Laptop Base Image" /verify

    Please note how this way the "named after date" folder will contain an image taken on the same date of the name of the folder, whilst in the original implementation the "named after date" folder would have contained "the image that was taken last time BEFORE the date in the name of the folder"

     

     

    jaclaz

    I like the idea,

     

    The only problem with this is that I have another batch file which deploys the captured image and that script pulls from the main folder such as i:\lenovo\base\blank\image.wim so say now the new image is in %Today% folder, I'll have to manually edit the script each time or copy and paste the image outside of the %Today% folder.

  9. Well, you cannot really really set "date" to a rearranged part of itself, "date" is an internal variable, you cannot redefine it ...

     

    Try with:

    SET MYdate=="%date:~10,4%-%date:~4,2%-%date:~7,2%"

    START /wait xcopy i:\lenovo\base\blank\image.wim i:\lenovo\base\blank\archive\%MYdate%\

     

    I am also not much convinced of the actual need to use XCOPY nor about needing to use START /WAIT (not even for the del command), you can simply MOVE the file, or if the idea is to first thing COPY it, then verify that the copy was successful (let's say by hashing both source and target) before DELeting the source, the verifying part is completely missing.

     

    jaclaz

     

    Edit: Ooops, crossposting with submix8c  :blushing:

     

    Thank you! I'll give this a try. I don't mind just moving the file instead. What command should I use for moving instead of xcopy? Also I forgot to mention, I do not no nothing about programing or batch script lol I just do this for fun and to make my life easier at work.

  10. Hello

     

    Could someone please help me fix this batch script below. I would really apperciate your help.

     

    We use imagex from microsoft for our imaging. This batch script copies captures the image I prepare which works fine. The 3 steps that don't work are "REM" lines in the script. 

     

    First REM should use the name as the current date

    Second REM should copy the previous image.wim file to an archive folder before deleting

    Third REM should delete the image.

     

    The way it works right now is the new image.wim file just gets overwritten on the previous image.wim and the script doesn't copy the previous image.wim file into the achrive folder before overwritting. Achrive is required just in case we need to go back to the old image.

    This is a windows 7 image. Please let me know if you need any additional information.

     

     

    echo off
    Title Capturing Laptop Base Image
    REM SET date="%date:~10,4%-%date:~4,2%-%date:~7,2%"
    REM START /wait xcopy i:\lenovo\base\blank\image.wim i:\lenovo\base\blank\archive\%date%\
    REM START /wait del i:\lenovo\base\blank\image.wim

    cls
    imagex /compress fast /capture D: i:\lenovo\base\blank\image.wim "Laptop Base Image" /verify
    PAUSE
    exit

×
×
  • Create New...