Jump to content

Yzöwl

Patron
  • Posts

    4,113
  • Joined

  • Last visited

  • Donations

    0.00 USD 
  • Country

    United Kingdom

Posts posted by Yzöwl

  1. Here's some batch script code, which you may find useful. It is based upon what I quickly read from the opening post, so I apologize if it is no longer valid.

    What it is supposed to do, is to use the built-in CertUtil command, (Windows Vista+), to perform the MD5 hashes.

    To use it, just run it with a single argument. If the argument is an existing directory, every file not named App.md5 in that directory and its subdirectories will be hashed. If it's an existing file argument and it isn't named App.md5, it will be hashed. If a non existing file or directory is passed, the script will treat it as if your argument was the current directory.

    The output, to App.md5, will be the full file path preceded with a semicolon and the hash on the line below it.

    @ECHO="%~a1"|"%__APPDIR__%FIND.EXE" "d">NUL&&(CALL :SUB "%~1" "/S" "%%%%#")||(
    	IF NOT EXIST "%~1" (CALL :SUB "%CD%" "/S" "%%%%#"
    		>NUL "%__APPDIR__%TIMEOUT.EXE" 3&GOTO :EOF
    	)ELSE IF /I "%~nx1"=="App.md5" (
    		ECHO Input file %~nx1 cannot be hashed, exiting...
    		>NUL "%__APPDIR__%TIMEOUT.EXE" 3&GOTO :EOF)
    	CALL :SUB "%~1" "" "%~1")
    @"%__APPDIR__%TIMEOUT.EXE" 3 >NUL&GOTO :EOF
    :SUB
    @(FOR /F "EOL=|DELIMS=" %%# IN ('DIR /B%~2/A-D-L-S "%~1"^
    	 ^|"%__APPDIR__%FINDSTR.EXE" /IV "\\App.md5$"')DO @FOR /F "DELIMS=" %%$ IN (
    	'^""%__APPDIR__%CERTUTIL.EXE" -HASHFILE "%~3" MD5 2^>NUL^|FIND /V ":"^"'
    )DO @SET "_=%%$"&ECHO ;%~3&CALL ECHO(%%_: =%%)>>"App.md5"
    

    Note: If you wish to change your filename from App.md5 you'll need to change it in three places, (lines 4, 11 & 13).

  2. I think you could use a similar method, instead using replace.exe from a for loop:

    @Echo Off & SetLocal EnableExtensions DisableDelayedExpansion
    
    :Loop
    Set "#="
    Set /P "=Please enter Y or N :"<Nul
    For /F Skip^=1^ Delims^=^ EOL^= %%$ In ('Replace ? . /U /W') Do If Not Defined # Set "#=%%$"
    Echo(
    If /I "%#%"=="Y" GoTo Entrey
    If /I "%#%"=="N" GoTo Entren
    GoTo Loop
    
    :Entrey
    Echo You entered Y & Pause
    GoTo :EOF
    
    :Entren
    Echo You entered N & Pause
    GoTo :EOF

     

  3. You could probably do this directly using this GetCOMs.cmd file Run as administrator:

    @ECHO OFF
    SETLOCAL ENABLEDELAYEDEXPANSION
    SET "_="
    FOR /F "SKIP=1TOKENS=2DELIMS=M" %%A IN ('WMIC /NAMESPACE:\\ROOT\WMI PATH^
     MSSERIAL_PORTNAME GET PORTNAME') DO FOR %%B IN (%%A) DO SET "_=!_!,%%B"
    IF DEFINED _ (IF "%_:~,1%"=="," SET "_=%_:~1%"
    	ECHO/"!_!">"%~dp0AllCOMs.txt")
    PAUSE

     

  4. To check if system protection is enabled, I would probably use the registry to determine if RPSessionInterval is greater than 0.

    In a batch file to enable system protection on the OS drive with a maximum 15% size I would try this As administrator:

    @ECHO OFF
    SET "rKey=HKLM\SOFTWARE\Microsoft\Windows NT\CurrentVersion\SystemRestore"
    SET "rVal=RPSessionInterval"
    SET "dVal="
    FOR /F "EOL=H Tokens=2*" %%# IN ('REG Query "%rKey%" /V "%rVal%" 2^>NUL'
    ) DO SET/A "dVal=%%$"
    IF NOT DEFINED dVal (ECHO ERROR! & PAUSE & EXIT/B)
    IF %dVal% EQU 0 (
    	WMIC /NameSpace:\\root\default PATH SystemRestore CALL Enable %SystemDrive%)
    VSSADMIN Resize Shadowstorage /For=%SystemDrive% /On=%SystemDrive% /MaxSize=15%%

    This is untested, (I am not telling you to change scripting language, just showing you a method of detection of the state of the mechanism).

  5. @nerio Here's a quick untested rewrite. (I have included code to do this for exe's and msu's containing the string -KB)

    It should auto create the "kb.txt" file, install only the msu's which were not output in that list before deleting the list.

    @ECHO OFF
    SETLOCAL ENABLEEXTENSIONS DISABLEDELAYEDEXPANSION
    
    IF /I NOT "%~dp0"=="%__CD__%" (PUSHD "%~dp0" 2>NUL && (SET _$=T) || GOTO :EOF)
    
    (	FOR /F "EOL=H DELIMS=" %%# IN ('WMIC.EXE QFE GET HOTFIXID') DO FOR %%$ IN (
    	%%#) DO ECHO=%%$)>"KB.TXT"
    
    IF NOT EXIST "KB.TXT" GOTO ENDIT
    
    SET "_=T"
    FOR /F "DELIMS=" %%# IN ('WHERE/F /R . *-KB*.MSU *-KB*.EXE') DO (SET "_N=%%~n#"
    	IF /I "%%~x#"==".MSU" SET "_X=WUSA.EXE"
    	SETLOCAL ENABLEDELAYEDEXPANSION
    	FINDSTR/IBC:"!_N:*-KB=KB!" "KB.TXT">NUL 2>&1 && (ENDLOCAL) || (
    		ECHO=INSTALLING !_N:*-KB=KB!
    		TIMEOUT 2 /NOBREAK>NUL
    		!_X! "%%#" /quiet /norestart
    		ENDLOCAL & SET "_="))
    
    DEL "KB.TXT"
    IF DEFINED _ GOTO ENDIT
    
    ECHO= == Press any key to restart ==
    PAUSE>NUL
    SHUTDOWN.EXE /r /t 0
    
    :ENDIT
    IF "%_$%"=="T" POPD
    GOTO :EOF

    Note: The above uses the WHERE and TIMEOUT commands with MSU's which were all post XP, if you are using XP then you'd need to replace:

    FOR /F "DELIMS=" %%# IN ('WHERE/F /R . *-KB*.MSU *-KB*.EXE') DO (SET "_N=%%~n#"
    	IF /I "%%~x#"==".MSU" SET "_X=WUSA.EXE"
    	SETLOCAL ENABLEDELAYEDEXPANSION
    	FINDSTR/IBC:"!_N:*-KB=KB!" "KB.TXT">NUL 2>&1 && (ENDLOCAL) || (
    		ECHO=INSTALLING !_N:*-KB=KB!
    		TIMEOUT 2 /NOBREAK>NUL
    		!_X! "%%#" /quiet /norestart
    		ENDLOCAL & SET "_="))

    with:

    FOR /F "DELIMS=" %%# IN ('DIR/B/S/A-D *-KB*.EXE') DO (SET "_N=%%~n#"
    	SETLOCAL ENABLEDELAYEDEXPANSION
    	FINDSTR/IBC:"!_N:*-KB=KB!" "KB.TXT">NUL 2>&1 && (ENDLOCAL) || (
    		ECHO=INSTALLING !_N:*-KB=KB!
    		>NUL PING -n 3 0.0.0.0
    		"%%#" /quiet /norestart
    		ENDLOCAL & SET "_="))
  6. My preference is to forget about the fancy console window GUI progress bar and instead use the console window title bar to update the end user.

    @Echo Off
    SetLocal EnableExtensions EnableDelayedExpansion
    Reg Query "HKU\S-1-5-19" 1>Nul 2>&1 || (PowerShell -ExecutionPolicy Bypass^
     -Command "SaPs -Verb RunAs -PSPath '%ComSpec%' -Args '/C """"%~f0""""'"
    	Exit/B)
    If /I "%CD%\" NEq "%~dp0" PushD %~dp0
    Set "bar="
    For /L %%a In (1,1,48) Do Set "bar=!bar!>"
    Set "n=0"
    For %%a In (*.msu) Do Set/A n+=1
    Set "i=0"
    Echo( Processing files:
    For %%a In (*.msu) Do (
    	Set/A i+=1, percent=i*100/n, barLen=48*percent/100
    	For %%b In (!barLen!) Do Title !percent!%%  !bar:~,%%b!
    	Echo( !i!- %%a
    	WUSA.EXE "%%a" /norestart /quiet)
    Title Press any key to exit . . .
    Timeout -1 1>Nul

    Hope this gives you a more sensible solution for your script.

  7. I wasn't offered KB2999226 or KB3050265 as they don't appear on my list nor are they installed. I have got KB3118401 installed although I see no reason why that would affect the WU Process.

  8. Interesting thought and one which I've never contemplated, the machine currently shows 6 updates for .NET Framework 4.6.1 and 236 updates for Windows including IE11, (installed but unopened).

    It's just that the Microsoft Official Fix for the 'slowness' problem is supposed to be one of the items in my above list, and the update which superseded it is also there too.

  9. My guess is that it's related to me refusing to install any of the following updates: (the windows update 'fixes' are supposed to be included among these anti telemetry/win10 upgrade updates).

    Quote

    kb971033     kb3035583     kb3075853     kb3102810
    kb2882822     kb3042058     kb3080149     kb3102812
    kb2902907     kb3044374     kb3081437     kb3112343
    kb2922324     kb3046480     kb3081454     kb3112336
    kb2952664     kb3058168     kb3081954     kb3123862
    kb2976978     kb3064683     kb3083324     kb3135445
    kb2977759     kb3065987     kb3083325     kb3135449
    kb2990214     kb3065988     kb3083710     kb3138612
    kb3012973     kb3068708     kb3083711     kb3138615
    kb3014460     kb3072318     kb3086255     kb3139929
    kb3015249     kb3074677     kb3088195     kb3146449
    kb3021917     kb3075249     kb3090045     kb3150513
    kb3022345     kb3075851     kb3093983

    …or any of May's updates yet!

    It took 2+ hours each time I ran the WU checks too!

  10. This is unimportant but I just thought I'd post it here because it's odd.

    XHGLiK8.png

    …Just as a note after three other WU runs all ending as above I was eventually offered 33 Important and 1 Optional update

  11. As you haven't provided sufficient information to persuade me otherwise could you explain why, if your intending to change settings for the interactive user, you aren't making changes to HKEY_CURRENT_USER\Software\Classes instead of HKEY_CLASSES_ROOT.

    Please be aware that this Member has also asked this question elsewhere. Could you please tell me why if you're only wanting to change these settings on the PC's of your Brother, Son, Wife and yourself why you would wish to script something that would take only 1 minute to perform on each of the four machines once.

  12. 22 hours ago, NoelC said:

    In Windows 8.1...

    If you run a scheduled task as a particular user, and if that user is not logged on at the time, when you use the %USERPROFILE% environment variable, in Win 8.1 you get the default user profile path.  In other words, where I would have expected USERPROFILE to be C:\Users\NoelC, instead it's delivered to the scheduled task as C:\Users\Default.

    USERNAME is set as expected (NoelC) though. 

    So if one wants to use the user profile area, one has to code the command: SET USERPROFILE=C:\Users\%USERNAME%

    Just in case there's been some sort of redirection as opposed to symbolic linking it may be worth not hardcoding the drive letter or even the \Users locations.

    Off the top if my head, (untested), something like this may do that:

    @For /F "Tokens=2 Delims=," %%a In ('WhoAmI /User /Fo CSV /NH') Do @(
    	For /F "Tokens=1* Delims==" %%b In (
    		'"WMIc Path Win32_UserProfile Where (SID='%%~a') Get LocalPath /Value"'
    	) Do @For %%d In (%%c) Do @Set UserProfile=%%d)
  13. 9 hours ago, NoelC said:

    Are you sure about that?  Do you have a specific KB number that fixes the problem?  Is it one of those below?

    <SNIP />

    -Noel

    Installing and searching for updates is slow and high CPU usage occurs in Windows 7 and Windows Server 2008 R2

    That specific update is included in the list in the next link. (The page is the source suggested as the definitive solution in the Topic on the subject in our Forum).

    Aegis for Windows 7/8.x - Block all known Microsoft spying and Windows 10 upgrade elements

  14. 1 hour ago, NoelC said:

    Actually it's worse than that...  For months now, Windows 7 Updates cause a hard-loop of a core for tens of minutes to hours, depending on how powerful your CPU is.  See this thread among several others on AskWoody.com:

    http://www.askwoody.com/2016/the-windows-update-takes-forever-problem/

    Trouble is that the official fix for it is contained within one of the updates we're asked to ignore as part of our 'say no to Win10' decision.

  15. But first you have to change execution policy in Powershell, otherwise it will return an information that the script cannot be run.

    Not necessary, just bypassing it would suffice should the Execution Policy be a problem.

     

    Example:

    @PowerShell -ExecutionPolicy Bypass -NoLogo -NonInteractive -NoProfile -WindowStyle Hidden -Command ".\New-SizedFile.ps1 %UserProfile%\Dummy.txt 1GB"
  16. Now that the general conversation has finished and because you hadn't specified your OS, I thought I'd mention using a (probably built-in) PowerShell script to create your file.

     

    New-SizedFile.ps1

    param( [string]$FilePath,[double]$Size )$file = [System.IO.File]::Create($FilePath)$file.SetLength($Size)$file.Close()

    Example Uses:

    Create Dummy.txt with size 698 bytes
    .\New-SizedFile.ps1 C:\Users\Yzöwl\Dummy.txt 698
     
    Create Dummy.txt with size 86 KB
    .\New-SizedFile.ps1 C:\Users\Yzöwl\Dummy.txt 86KB
     
    Create Dummy.txt with size 20 MB
    .\New-SizedFile.ps1 C:\Users\Yzöwl\Dummy.txt 20MB
     
    Create Dummy.txt with size 3 GB
    .\New-SizedFile.ps1 C:\Users\Yzöwl\Dummy.txt 3GB
×
×
  • Create New...