Custom Sysprep Image Assistance

Discussion in 'Scripting' started by kpoverdorf, Apr 16, 2014.

  1. kpoverdorf

    kpoverdorf MDL Novice

    Apr 4, 2014
    16
    3
    0
    #1 kpoverdorf, Apr 16, 2014
    Last edited by a moderator: Apr 20, 2017
    Hello everyone!

    I am currently looking for some assistance/guidance in creating a personal Win7 image. I know the sysprep part of this may not be in the right section but how I am applying my image involves "coding". If I am going about this process all wrong please tell me.

    I work on a lot of family/friends computers and I am looking to cut a lot of time out of the imaging process. I have been using a Sysprep image at work for a while and it has worked very well. But there is far less customization and no need for an OOBE image at work.

    So here I am… I will provide my current sloppy and partially unsuccessful image process in hopes that someone will be able to help.

    Currently my image process is as follows.
    1. Config image with desired software and settings
    2. Save Auto_Image.bat to startup folder and ExtendC.txt to C:\TEMP (code found below).
    3. Run sysprep using the following command -
      Code:
       %windir%\system32\sysprep\sysprep.exe /generalize /audit /shutdown /quiet /unattend:F:\DefaultProfile.xml
    4. Capture image using CloneZilla (whole disk).
    5. When the image applied it will do the following:
      • Boot to audit mode
      • Kill the Sysprep process.
      • Extend the C: drive partition to remaining free space on HDD
      • Activate Office and Windows (not working)
      • Delete ExtendC.txt
      • Run Sysprep OOBE, Reboot
      • Delete Auto_Image.bat
    6. The computer reboots presenting me with an OOBE where I can create the user account specific to that PC.
    7. Done.

    Here is the content of the BAT and the TXT files mentioned above.

    Auto_Image.bat
    Code:
    ::==============================================================
    ::This batch file will do the following:
    ::             1) Kill the Sysprep process.
    ::             1) Extend the C: drive partition to remaining free space on HDD
    ::             2) Activate Office and Windows
    ::             3) Delete ExtendC.txt
    ::             4) Run Sysprep OOBE, Reboot
    ::             5) Delete Auto_Image.bat
    ::Prep for this script:
    ::             1) Place ExtendC.txt in C:\TEMP
    ::             2) Place a copy of this Bat file in "C:\ProgramData\Microsoft\Windows\Start Menu\Programs\Startup"
    ::             3) Install AutoKMS using Microsoft Toolkit.
    ::===============================================================
    ; @echo off
    ; Taskkill /IM sysprep.exe /F
    DISKPART.exe /s C:\TEMP\ExtendC.txt
    ; C:\Windows\AutoKMS\AutoKMS.exe /EZActivator
    ; Del /Q C:\TEMP\ExtendC.txt
    ; %windir%\system32\sysprep\sysprep.exe /oobe /reboot
    ; Del /Q C:\ProgramData\Microsoft\Windows\"Start Menu"\Programs\Startup\Auto_Image.bat
    ; EXIT
    
    ExtendC.txt
    Code:
    select disk 0
    select partition 2
    extend
    Exit
    
    My current issue is when I run the AutoKMS command it activates Office and Windows but then throws an error and crashes stopping the entire process. The error being “No mapping between account names and security IDs was done. (Exception from HRESULT: 0x80070534)”. I think what is happening is, it’s unable to create the scheduled task in Audit mode.

    Best case scenario, I would have this entire process completed when the user first logs in after the OOBE. The issue is UAC gets fussy at every command. I’m sure there is a way to bypass that but everything I read is a little over my head.

    I’m expecting someone to tell me I am making this very difficult for myself. If anyone could assist that would be great.
     
  2. xinso

    xinso MDL Guru

    Mar 5, 2009
    3,930
    5,282
    120
    #2 xinso, Apr 17, 2014
    Last edited by a moderator: Apr 20, 2017
    How about moving C:\Windows\AutoKMS\AutoKMS.exe /EZActivator to %SystemRoot%\Setup\Scripts\SetupComplete.cmd?
     
  3. kpoverdorf

    kpoverdorf MDL Novice

    Apr 4, 2014
    16
    3
    0
    Not sure if thats an option since that is the default location for the utility and I'm not trying to break its functionality.
     
  4. s1ave77

    s1ave77 MDL Guide Dog/Dev

    Aug 15, 2012
    14,678
    18,890
    340
    xinso is on the right path. That way i'm doing this by using setupcomplete.cmd to copy from the \Scripts\ folder to it's location and run it the first time.
     
    Stop hovering to collapse... Click to collapse... Hover to expand... Click to expand...
  5. kpoverdorf

    kpoverdorf MDL Novice

    Apr 4, 2014
    16
    3
    0
    Yea... I'm probably going to scrap this entire project and start all over. I feel like everything I want/need done could be done post OOBE at the users desktop using the right methods. Pretty much knowing nothing about scripting/programming is making it near impossible to understand the solutions I am receiving and finding online. Simple batch files running basic commands arent going to cut it. So I will probably have to learn more before I even attempt this.

    Thanks for trying to help.
     
  6. s1ave77

    s1ave77 MDL Guide Dog/Dev

    Aug 15, 2012
    14,678
    18,890
    340
    Not that difficult. When in Audit Mode you can create \Windows\Setup\Scripts\ folder and place setupcomplete.cmd (simple batch script file :D) and the files needed there. It will be processed during Windows Setup right after the system is installed (SetupComplete Stage). A firstlogon.cmd at the same place will be processed at FistLogon Stage which is the first LogOn to the new user account.
     
    Stop hovering to collapse... Click to collapse... Hover to expand... Click to expand...
  7. kpoverdorf

    kpoverdorf MDL Novice

    Apr 4, 2014
    16
    3
    0
    #7 kpoverdorf, Apr 17, 2014
    Last edited by a moderator: Apr 20, 2017
    (OP)

    Ok so let me see if I follow you....

    You are saying... copy the AutoKMS.exe to "%SystemRoot%\Setup\Scripts\" along with setupcomplete.cmd (with the following code) and my ExtendC.txt. Create an OOBE image and capture it at shutdown and on boot it will ready the OOBE image and run setupcomplete.cmd before even getting to the user login. Thus completing those couple commands uninterrupted by UAC and out of sight.

    Code:
    ; @echo offDISKPART.exe /s %SystemRoot%\Setup\Scripts\ExtendC.txt
    
    ; %SystemRoot%\Setup\Scripts\AutoKMS.exe /EZActivator
    
    ; Del /Q %SystemRoot%\Setup\Scripts\ExtendC.txt
    
    ; EXIT
     
  8. s1ave77

    s1ave77 MDL Guide Dog/Dev

    Aug 15, 2012
    14,678
    18,890
    340
    #8 s1ave77, Apr 17, 2014
    Last edited by a moderator: Apr 20, 2017
    Yep that way it should work. The setupcomplete.cmd should look like this:

    Code:
    @echo off
    pushd "%~dp0"
    DISKPART.exe /s <ExtendC.txt
    md "%windir%\AutoKMS"
    xcopy AutoKMS.exe /s /q "%windir%\AutoKMS\" /Y
    %windir%\AutoKMS\AutoKMS.exe /EZActivator
    rd /s /q "%windir%\Setup\Scripts"
    exit
    
     
    Stop hovering to collapse... Click to collapse... Hover to expand... Click to expand...
  9. kpoverdorf

    kpoverdorf MDL Novice

    Apr 4, 2014
    16
    3
    0
    #9 kpoverdorf, Apr 17, 2014
    Last edited by a moderator: Apr 20, 2017
    (OP)
    I'm gonna try this. Wish I knew about this method before... lol
     
  10. s1ave77

    s1ave77 MDL Guide Dog/Dev

    Aug 15, 2012
    14,678
    18,890
    340
    Use this way myself as having the files inside the install.wim prevents them from being detected :cool2:. To change anything later the install.wim file can be mounted to a folder with dism.exe :good3:. Faster than going the Audit Mode Route.
     
    Stop hovering to collapse... Click to collapse... Hover to expand... Click to expand...
  11. kpoverdorf

    kpoverdorf MDL Novice

    Apr 4, 2014
    16
    3
    0
    I'll have to explore that method.
     
  12. kpoverdorf

    kpoverdorf MDL Novice

    Apr 4, 2014
    16
    3
    0
    The script seemed to work with the exception of the Diskpart command. I will troubleshoot it a little, maybe there was a typo or something.
     
  13. kpoverdorf

    kpoverdorf MDL Novice

    Apr 4, 2014
    16
    3
    0
    Ahh yes, "<ExtendC.txt" was the typo. Fixed that and it worked perfectly. Thank you!
     
  14. s1ave77

    s1ave77 MDL Guide Dog/Dev

    Aug 15, 2012
    14,678
    18,890
    340
    OK :good3:. Wasn't sure about syntax when a silent switch is used for diskpart. Good to see you figured it out :D.
     
    Stop hovering to collapse... Click to collapse... Hover to expand... Click to expand...
  15. stayboogy

    stayboogy MDL Addicted

    May 1, 2011
    709
    115
    30
    #15 stayboogy, Apr 29, 2014
    Last edited: Apr 30, 2014
    (forgive if none of this is relevant to you)

    I do this kind of thing myself for friends, family, customers, and even myself. (only for windows 7 do I this though. haven't messed with it for windows 8)

    Let's say I want to make a new custom image for a friend with just office, a few handy programs (or a lot, doesn't matter) and tweaks to make the experience a little better, but one that I will use for people in the future as well.

    1) I'll fully install windows and use a very generic user name like "user" in setup, install office, and all the programs, and perform all the necessary updates, and all my tweaks. (I do not use the audit function of sysprep because I can see no reason why one would need to the way I do it.)

    2) Then I'll use Daz's loader from an external source and activate the system.

    3) Next I'll use Microsoft Toolkit to activate office and install kms.

    4) Then I'll do one final reboot and when the system is loaded I run sysprep with only "/generalize /shutdown" and not the /oobe. (I don't really see a need for the /oobe part if I'm making this image to use for people I know or even customers because ultimately they do not care to have to go through entering a user name and all that when they get back on their machine.)

    5) I'll then boot into my pe environment and (g)imagex the system.

    For all general intents, the image is just like it needs to be for any machine I install it on.

    Now, when it comes time to deploy said image, I load up my pe environment, take care of all the partitioning necessary and apply the image. When I reboot the machine I verify that all the configuration processes finish nicely, and once the system is booted fully I just change the user name, activate Windows with Daz's loader since it won't survive an image apply usually (Office stays activated through the apply using KMS from Microsoft Toolkit) and power off the machine. The new image is installed with all custom programs and settings, including the new user's name, all software is activated and the process is done.
     
    Stop hovering to collapse... Click to collapse... Hover to expand... Click to expand...
  16. kpoverdorf

    kpoverdorf MDL Novice

    Apr 4, 2014
    16
    3
    0
    I received your first comment, not sure why you deleted it.

    I use this method for 2 reasons. Time and I may not be aware of my other options. My purpose for this was to save time during my imaging process so my wife doesn't get fussy that I am fiddling with computers all day (to name one). Overall, a faster more efficient imaging process is a must for a tech. However, while I feel like my methods are effective I understand that they may not be the best available. That's where my lack of knowledge comes into play and I am aware of that.

    Here is the process in a nutshell:
    1. Apply image to computer using clonezilla
    2. Computer reboots to OOBE
    3. Add user info
    4. Boot to desktop
    5. Finish MSE OOBE setup and tell CCleaner to skip UAC. (I could prob silent install MSE not sure about the CCleaner setting though.)
    6. Give the computer to the user.
    The time to complete varies depending on the hardware but this easily takes less than an hour. I'd say thats decent.

    This image includes EVERYTHING I need the user to have and it's a custom profile so if they make a new user account they will get the same settings (my favorite part). Oh, and this is Win7. If the person asked for software not in my image I can install that after configuring MSE and CCleaner, no biggie. I don't ever really give a user a computer with out creating their account and making sure everything is running well. The OOBE process is more for me so I don't have to make a temp/Admin account and then make their account and delete/disable the account. Also, not sure about the need for Daz's loader and MTK. I just use MTK and have it auto activate Windows and Office during boot.

    The most time consuming part of this is creating the image (which is done). Besides that, applying the image using clonezilla takes time. But even then, I don't have to be present for that. So this is the most efficient (time saving) method I know to date. I dont always know who's computer I will be working on, so this image is generic enough that I can apply it to any computer but still have all the settings/software I want the user to have. Still need to test it on a SSD though.

    The process you described in your comment seems to be a little different but the end result is basically the same. I use audit mode because it's what I learned to use and it has always worked for me.

    Thanks for your concern though.
     
  17. stayboogy

    stayboogy MDL Addicted

    May 1, 2011
    709
    115
    30
    it was late and i was tired and didn't think i was making any sense at all.

    anyway, thanks for the information--i never thought of just using Microsoft Toolkit for both Windows and Office, even though i clearly know kms survives an image apply. a "duh" moment for me indeed.

    but

    i have some scripts that i grabbed from some tutorial somewhere sometime ago that can automate the image process for you using imagex from a simple pe 3.0 environment. it's actually pretty fast in my opinion--about 9 minutes to make image on basic hardware with a fully customized and updated windows 7 sp1 install. i use it to create oem-type recovery partitions for my family and customers so they can do the restore themselves without touching anything but the down arrow key once at boot, and the Y key once when it asks to begin the process.

    i don't have the link to give credit to whoever come up with it, but i have the scripts and files if you'd be interested. very simple and basic.

    you could possibly improve them for your own usage should you need to make another image or if you'd like to make the recovery partition like i do.
     
    Stop hovering to collapse... Click to collapse... Hover to expand... Click to expand...
  18. kpoverdorf

    kpoverdorf MDL Novice

    Apr 4, 2014
    16
    3
    0
    HA! I understand. At first I liked the idea of a recovery partition but knowing the people I deal with it would cause more issues than anything. I would rather not give the user too much "power" as they usually end up ruining a good thing.
     
  19. stayboogy

    stayboogy MDL Addicted

    May 1, 2011
    709
    115
    30
    it's virtually fool-proof actually. but i know what you mean it won't let the user do anything other than accept the recovery or reject it and reboots like normal.

    i did find the link for the basic tutorial i followed and files i use. mine is modified from this though slightly. i removed user options and ugly menu and dialogs.

    http://www.rmprepusb.com/tutorials/auto_restore

    here are the files i use (everything but my pe boot.wim): https://www.mediafire.com/?365j4bdgbsw6rdq
     
    Stop hovering to collapse... Click to collapse... Hover to expand... Click to expand...