Tuesday, July 16, 2024

2024-07-16 - Prank Scripts

     One day in class several months ago, I left my laptop logged in and went to the bathroom. No one had ever touched my stuff before in an objectionable way so I didn't worry about it. Unbeknownst to me, this is a thing Doug takes advantage of at his job at BYU all the time as an administrator. He likes to teach people lessons so they learn to be better. So he wrote a bunch of scripts which he keeps on a jump drive, handy and ready at a moments notice so he can go onto someone's computer and plug in his thumb drive and activate any of like fifty scripts he has written to make life difficult for the person when they get back to their computer,. The one he activated on me was the one that locked my screen every ten seconds when logged in. So ten seconds after I logged in, it logged me back out, and this process would repeat until the problem was solved. 

    Ultimately the fix was actually pretty simple, you just go into task manager and end a background process using the command prompt and the shenanigans end abruptly. 

    A note about this, no CMD was open while it was doing this, it did it 'silently'. So to the uninitiated, this just looks like some sudden Windows error that requires a reboot. And I don't know, I never tried this, but a reboot would probably fix it. But it would be funny if Doug somehow found a way to keep it activated through a reboot. I wouldn't put it past him. 

    After he did this I asked him if I could have a copy of that script and he said no. I asked why not and he said because I want you to learn how to write them yourself. I asked him what he did to write his and he told me he wanted me to figure it out myself. But, he said, even though usually he discourages using ChatGPT when troubleshooting, he said that actually in this case, ChatGPT would be fine. 

    So I did set out to try and start doing this. 

    I started by straight up asking ChatGPT to write a script in Bash that does what I want. And it did, but it wasn't perfect. This does happen to be one of ChatGPT's selling points, that you can tell it what program or script you want it to write in and it'll do it. And supposedly, it'll work, it just won't be super clean. Well, I will amend that. It will look like it should. But it will likely add stuff that doesn't need to be added, things that seem like they should work won't because of an update or because the OS has changed and doesn't do things that way anymore, or it'll use a method that isn't used much anymore because there's a better one because it thinks that you meant this when you didn't think that it mattered and so you thought it would assume that instead or whatever. This is why you need to know how to code yourself if using it. But this doesn't mean that you're a lost cause if you don't know how to code. This can help. But Doug has recommended to me that he just wants me to use it and then look at everything ChatGPT is doing, go through the code it created for me, and make sure I understand what it's doing. You can even ask it about each part. 

    I wrote several iterations. Unfortunately it didn't occur to me several months ago when doing this to write about what I did, so I can't actually say for sure what I did. Okay. I did this in early May apparently. I will append what conversations I had with ChatGPT about two scripts I created. 

    Now, I did ask Doug what scripts I could create, and he told me he didn't want to tell me anything I would find too challenging, he wanted me to have a fighting chance of figuring out how to do it myself so he suggested I start with an annoying capslock auto-activation and deactivation every ten seconds. So I did. Here's the ChatGPT conversation from that, which includes the code it gave me and things I said to ask it to change. 

I'd like to create a batch script that toggles caps lock every five seconds.
ChatGPT

Sure, you can create a batch script to toggle Caps Lock every five seconds. Here's how you can do it:

batch

@echo off
:loop
echo Toggling Caps Lock
powershell -command "[console]::CapsLock.toggle()"
timeout /t 5 /nobreak >nul
goto loop

Save this script with a .bat extension (e.g., toggle_capslock.bat) and run it. It will toggle Caps Lock every five seconds. You can stop the script by closing the command prompt window or pressing Ctrl+C.

 

Powershell said: Method invocation failed because [System.Boolean] does not contain a method named 'toggle'.
ChatGPT

Apologies for that oversight. Let's use a different approach. Here's an updated version of the script:

batch

@echo off
set "Toggle=0"
:loop
if %Toggle%==0 (
echo Turning Caps Lock on
set "Toggle=1"
) else (
echo Turning Caps Lock off
set "Toggle=0"
)
powershell -command "[console]::CapsLock = %Toggle%"
timeout /t 5 /nobreak >nul
goto loop

This script toggles Caps Lock by changing its state between on and off every five seconds. Save it as a .bat file and run it.

 

does this script stop running just by closing the shell?
ChatGPT

No, this script will continue running even if you close the command prompt window. To make it stop when the window is closed, you can catch the CTRL_CLOSE_EVENT and exit gracefully. Here's the updated script:

batch

 

@echo off
setlocal EnableDelayedExpansion
REM Register a CTRL_CLOSE_EVENT handler
set "handler=toggle_capslock_handler"
powershell -Command "Register-EngineEvent -SourceIdentifier ([Microsoft.PowerShell.ConsoleHost]::Closing) -Action { & '%handler%' }"
REM Initialize toggle state
set "Toggle=0"
:loop
if !Toggle! == 0 (
echo Turning Caps Lock on
set "Toggle=1"
) else (
echo Turning Caps Lock off
set "Toggle=0"
)
powershell -command "[console]::CapsLock = $(!Toggle!)"
timeout /t 5 /nobreak >nul
goto loop
:toggle_capslock_handler
REM Unregister the event handler and exit
powershell -Command "Unregister-Event -SourceIdentifier ([Microsoft.PowerShell.ConsoleHost]::Closing)"
exit /b

This script registers a handler for the CTRL_CLOSE_EVENT, so when you close the command prompt window, it will gracefully unregister the event handler and exit the script. Save it as a .bat file and run it.

 

how do I make it stop step by step in layman terms
ChatGPT

To make the script stop step by step, we'll add a way to stop it when you want. Let's add a simple mechanism: Pressing any key will stop the script.

Here's the modified script:

batch

@echo off
setlocal EnableDelayedExpansion
REM Register a CTRL_CLOSE_EVENT handler
set "handler=toggle_capslock_handler"
powershell -Command "Register-EngineEvent -SourceIdentifier ([Microsoft.PowerShell.ConsoleHost]::Closing) -Action { & '%handler%' }"
REM Initialize toggle state
set "Toggle=0"
REM Show a message indicating how to stop the script
echo Press any key to stop the script.
:loop
if !Toggle! == 0 (
echo Turning Caps Lock on
set "Toggle=1"
) else (
echo Turning Caps Lock off
set "Toggle=0"
)
powershell -command "[console]::CapsLock = $(!Toggle!)"
timeout /t 5 /nobreak >nul
REM Check if a key has been pressed, if so, exit the loop
if defined stop (
goto :toggle_capslock_handler
) else (
goto :loop
)
:toggle_capslock_handler
REM Unregister the event handler and exit
powershell -Command "Unregister-Event -SourceIdentifier ([Microsoft.PowerShell.ConsoleHost]::Closing)"
exit /b

Now, when you run the script, it will display a message saying "Press any key to stop the script." Once you press any key, the script will stop.

 

I don't want it to be that easy to stop the script. I want it to run without the prompt open, and to stop by killing it in the task manager, located next to system tasks.
ChatGPT

Got it. We'll modify the script to run silently in the background without any visible prompt, and it will only stop when you manually end it through the Task Manager.

Here's the updated script:

batch

@echo off
REM Register a CTRL_CLOSE_EVENT handler
set "handler=toggle_capslock_handler"
powershell -Command "Register-EngineEvent -SourceIdentifier ([Microsoft.PowerShell.ConsoleHost]::Closing) -Action { & '%handler%' }"
REM Initialize toggle state
set "Toggle=0"
:loop
if %Toggle%==0 (
powershell -command "[console]::CapsLock = $true"
set "Toggle=1"
) else (
powershell -command "[console]::CapsLock = $false"
set "Toggle=0"
)
timeout /t 5 /nobreak >nul
goto :loop
:toggle_capslock_handler
REM Unregister the event handler and exit
powershell -Command "Unregister-Event -SourceIdentifier ([Microsoft.PowerShell.ConsoleHost]::Closing)"
exit /b

With this script, there will be no visible prompt or indication that the script is running. It will continue toggling the Caps Lock state every 5 seconds until you manually end it through the Task Manager.

 

Why is it using powershell in the script? this is a .bat file running in cmd.
ChatGPT

You're correct. We don't need PowerShell commands within a batch script to toggle Caps Lock. Here's a revised version of the script that only uses native batch commands:

batch

@echo off
REM Register a CTRL_CLOSE_EVENT handler
set "handler=toggle_capslock_handler"
powershell -Command "Register-EngineEvent -SourceIdentifier ([Microsoft.PowerShell.ConsoleHost]::Closing) -Action { & '%handler%' }"
REM Initialize toggle state
set "Toggle=0"
:loop
if %Toggle%==0 (
echo Turning Caps Lock on
set "Toggle=1"
) else (
echo Turning Caps Lock off
set "Toggle=0"
)
rem Simulating Caps Lock key press
powershell -command "$wsh = New-Object -ComObject WScript.Shell; $wsh.SendKeys('{CAPSLOCK}')"
timeout /t 5 /nobreak >nul
goto :loop
:toggle_capslock_handler
REM Unregister the event handler and exit
powershell -Command "Unregister-Event -SourceIdentifier ([Microsoft.PowerShell.ConsoleHost]::Closing)"
exit /b

This script uses the SendKeys method from Windows Script Host (via PowerShell) to simulate pressing the Caps Lock key. The rest of the functionality remains the same as in the previous script. This version will work within a batch script without relying on PowerShell commands.

 

This script worked however it is running in an open window. What command makes it run silently and can you give me that altered script?
ChatGPT

To make the script run silently without displaying any window, you can use a utility called nircmd along with a technique called "self-deleting batch files". Here's the altered script:

batch

@echo off
REM Register a CTRL_CLOSE_EVENT handler
set "handler=toggle_capslock_handler"
powershell -Command "Register-EngineEvent -SourceIdentifier ([Microsoft.PowerShell.ConsoleHost]::Closing) -Action { & '%handler%' }"
REM Initialize toggle state
set "Toggle=0"
:loop
if %Toggle%==0 (
echo Turning Caps Lock on
set "Toggle=1"
) else (
echo Turning Caps Lock off
set "Toggle=0"
)
rem Simulating Caps Lock key press
powershell -command "$wsh = New-Object -ComObject WScript.Shell; $wsh.SendKeys('{CAPSLOCK}')"
timeout /t 5 /nobreak >nul
goto :loop
:toggle_capslock_handler
REM Unregister the event handler and exit
powershell -Command "Unregister-Event -SourceIdentifier ([Microsoft.PowerShell.ConsoleHost]::Closing)"
REM Deleting the batch file
del "%~f0"
exit /b

And here's how you run it silently:

Download nircmd from NirSoft and place the executable (nircmd.exe) in the same directory as your batch script.
Create a shortcut for your batch script.
Right-click on the shortcut, choose "Properties", and in the "Target" field, add cmd /c start /min before the path to your batch script. For example:
bash

 

cmd /c start /min "Path\to\your\batch\script.lnk"

This will launch the batch script minimized without any window visible. When the script finishes executing, it will automatically delete itself.

the cmd is still coming up. Is there a way to do this using %SystemRoot%\System32\cmd.exe for which is defined by Windows default the environment variable ComSpec with that file name as value. cmd.exe?
ChatGPT

Yes, you can utilize %ComSpec% to execute the batch script silently. Here's the updated script:

batch

@echo off
REM Register a CTRL_CLOSE_EVENT handler
set "handler=toggle_capslock_handler"
powershell -Command "Register-EngineEvent -SourceIdentifier ([Microsoft.PowerShell.ConsoleHost]::Closing) -Action { & '%handler%' }"
REM Initialize toggle state
set "Toggle=0"
:loop
if %Toggle%==0 (
echo Turning Caps Lock on
set "Toggle=1"
) else (
echo Turning Caps Lock off
set "Toggle=0"
)
rem Simulating Caps Lock key press
powershell -command "$wsh = New-Object -ComObject WScript.Shell; $wsh.SendKeys('{CAPSLOCK}')"
timeout /t 5 /nobreak >nul
goto :loop
:toggle_capslock_handler
REM Unregister the event handler and exit
powershell -Command "Unregister-Event -SourceIdentifier ([Microsoft.PowerShell.ConsoleHost]::Closing)"
REM Deleting the batch file
del "%~f0"
exit /b

And here's how you can execute it silently using %ComSpec%:

batch

%ComSpec% /c start /min "Title" "Path\to\your\batch\script.bat"

Replace "Title" with any title you want for the window (can be empty), and "Path\to\your\batch\script.bat" with the path to your batch script. This command will run the batch script silently without displaying any window.

 

It said this: Unable to find type [Microsoft.PowerShell.ConsoleHost]. At line:1 char:41 + ... neEvent -SourceIdentifier ([Microsoft.PowerShell.ConsoleHost]::Closin ... + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + CategoryInfo : InvalidOperation: (Microsoft.PowerShell.ConsoleHost:TypeName) [], RuntimeException + FullyQualifiedErrorId : TypeNotFound
ChatGPT

It seems there's an issue with the PowerShell command in the script. Let's simplify it to unregister the event handler and remove the dependency on PowerShell's console host. Here's the updated script:

batch

@echo off
REM Initialize toggle state
set "Toggle=0"
:loop
if %Toggle%==0 (
echo Turning Caps Lock on
set "Toggle=1"
) else (
echo Turning Caps Lock off
set "Toggle=0"
)
rem Simulating Caps Lock key press
powershell -command "$wsh = New-Object -ComObject WScript.Shell; $wsh.SendKeys('{CAPSLOCK}')"
timeout /t 5 /nobreak >nul
goto :loop
:cleanup
REM Deleting the batch file
del "%~f0"
exit /b

Then, you can run it silently using %ComSpec% like this:

batch

 

%ComSpec% /c start /min "Title" "Path\to\your\batch\script.bat"

Replace "Title" with any title you want for the window (can be empty), and "Path\to\your\batch\script.bat" with the path to your batch script. This command will run the batch script silently without displaying any window.

 

OKAY BUT i CANT USE ANY COLINS OR SLASHES IN FILE NAMES
ChatGPT

I see, let's simplify the script and make sure it can run without colons or slashes in the file names:

batch

@echo off
REM Initialize toggle state
set "Toggle=0"
:loop
if %Toggle%==0 (
echo Turning Caps Lock on
set "Toggle=1"
) else (
echo Turning Caps Lock off
set "Toggle=0"
)
rem Simulating Caps Lock key press
powershell -command "$wsh = New-Object -ComObject WScript.Shell; $wsh.SendKeys('{CAPSLOCK}')"
timeout /t 5 /nobreak >nul
goto :loop
:cleanup
REM Deleting the batch file
del "%~f0"
exit /b

You can run this script silently using %ComSpec% as before:

batch

 

%ComSpec% /c start /min "" "Path_to_your_batch_script.bat"

Replace "Path_to_your_batch_script.bat" with the actual path to your batch script. This command will run the batch script silently without displaying any window.

 

I want the script to activate immediately and then continue every ten seconds
ChatGPT

Got it. Here's the modified script to activate Caps Lock immediately and then toggle it every ten seconds:

batch

@echo off
REM Turn on Caps Lock initially
powershell -command "$wsh = New-Object -ComObject WScript.Shell; $wsh.SendKeys('{CAPSLOCK}')"
REM Infinite loop to toggle Caps Lock every ten seconds
:loop
timeout /t 10 /nobreak >nul
REM Simulating Caps Lock key press to toggle
powershell -command "$wsh = New-Object -ComObject WScript.Shell; $wsh.SendKeys('{CAPSLOCK}')"
goto :loop

This script will turn on Caps Lock immediately upon execution and then toggle it every ten seconds. There is no need for a separate cleanup section as the script will keep running until you manually stop it."


    Now, ultimately, the code I did end up with looked like this i Batch:

@echo off


REM Initialize toggle state

set "Toggle=0"


:loop

if %Toggle%==0 (

    echo Turning Caps Lock on

    set "Toggle=1"

) else (

    echo Turning Caps Lock off

    set "Toggle=0"

)

rem Simulating Caps Lock key press

powershell -command "$wsh = New-Object -ComObject WScript.Shell; $wsh.SendKeys('{CAPSLOCK}')"

timeout /t 5 /nobreak >nul

goto :loop

    And this code did work. There was a problem, it displayed the CMD, which we wanted to be silent and in the background. This is where Doug sggested that I write a second script to go with it' which will tell the computer to run it in the background. 

    This second scr4ipt was in VBS:

CreateObject("Wscript.Shell").Run """" & WScript.Arguments(0) & """", 0, False

     That was the whole script. And the to activate both scripts, Doug helped me write a third script to go with it which would activate both of those scripts. This was in Batch. 

copy capslock_every_5_seconds.bat %temp%\capslock.bat

start invis.vbs "%temp%\capslock.bat"

 This worked. But then there was a new problem. We tried it on multiple computers and it worked great, we were about to open bottles of wine and all that crap when I went and grabbed my thumb drive from the computer running the script at that tine and made a terrible discovery. The script deactivates the second you pull the drive hosting it. So since everything is running of the thumb drive and now it's gone, the whole point of the script is null and void. I am supposed to be able to go up to a computer, quickly plug this in and run any of the scripts I wish, and pull the drive and walk away with no evidence I did anything, except that now the computer is misbehaving until you cancel the process. So that's not happening. 

    I ended up not resolving this issue for the past few months because I got all the parts I needed for my weather display project and we got to work on that. And it took so much work and ideas and so many pieces and planning were involved that this whole prank script fell out of my head. I did remember that was a thing but I just completely forgot about it due to all the other many things I had to worry about, such as passing CompTIA A+ Core II at the time. So all extra time then only went to the weather display and all serious classwork went to passing the certification. 

    However, getting the Flipper Zero reinvigorated my desire to continue this on a more immediate basis because I want prank scripts to load into it and have it inject. 

    However I did work on a second script the next day that also technically did work but also suffered from the same problem of deactivating the second the thumb drive containing it was removed. Doug and I worked on trying to write into code to get it to plant itself in a temp file on windows computers even once the drive is pulled so it continues, but this seemed to do nothing. 

    So here's the ChatGPT conversation for the second script:

I want to create another script. This one will log your computer user off every ten seconds once logged in. It needs to run silently, on other wirds, no command prompt, using a seperate vbs script that simply comtains "CreateObject("Wscript.Shell").Run """" & WScript.Arguments(0) & """", 0, False", then a .bat script that actually activates the log off.ChatGP

 

Certainly! Here's how you can achieve that:
  1. First, create a VBScript file (let's name it silent.vbs) with the content:
vbs

CreateObject("Wscript.Shell").Run """" & WScript.Arguments(0) & """", 0, False

This script will run another script silently without displaying any command prompt.

  1. Then, create a batch file (let's name it logoff.bat) with the content:
batch

 

 
@echo off :loop timeout /t 10 /nobreak >nul cscript //nologo silent.vbs "shutdown.exe /l" goto loop

This batch file will run the VBScript silently every 10 seconds, which in turn will execute the command to log off the user (shutdown.exe /l).

Place both files (silent.vbs and logoff.bat) in the same directory. When you run logoff.bat, it will continuously log off the user every 10 seconds silently.

 

how is this process going to show up in task manager? I can just cancel this by ending it in task manager right?

ChatGPThe process will indeed show up in Task Manager, typically as cscript.exe (for the VBScript execution) and cmd.exe

Yes, you can end the process from Task Manager to stop the logoff script. In Task Manager, you can find the processes under the "Processes" tab, typically listed as cscript.exe and cmd.exe. However, if someone is actively monitoring Task Manager, they could potentially identify and terminate the process.

I tried running this. my computer did a security warning prompt every time it was about to activate so it wouldn't do it automatically and then once I clicked run, it would then open the cmd which is unacceptable, and showed in cmd the file path where I am storing the script, and then: wscript.exe "invis.vbs" "logoff.bat"

 

ChatGPT

Got it, it seems like the security settings on your system are causing the issue. To work around this, you can try a different approach by using PowerShell, which might bypass the security warnings.

First, let's create a PowerShell script to run the logoff command silently. Here's how you can do it:

  1. Create a PowerShell script file (let's name it logoff.ps1) with the following content:
powershell

$logoffCommand = "shutdown.exe /l" $shell = New-Object -ComObject "WScript.Shell" $shell.Run($logoffCommand, 0, $false)

This script will log off the current user silently when executed.

Next, create a batch file to continuously run the PowerShell script every 10 seconds without showing any command prompt. Here's how:

  1. Create a batch file (let's name it logoff.bat) with the following content:
batch

@echo off :loop powershell.exe -WindowStyle Hidden -File "logoff.ps1" timeout /t 10 >nul goto loop

This batch file will continuously run the PowerShell script every 10 seconds without displaying any command prompt.

Place both files (logoff.ps1 and logoff.bat) in the same directory. When you run logoff.bat, it will start logging off the user every 10 seconds without displaying any visible prompts or windows.

 

forget the silent.vbs thing, just make me a .bat script that locks the screen every ten seconds after someone re-enters their login.

ChatGPT

Sure, here's a batch script that will lock the screen every ten seconds after someone logs in:

batch

 

@echo off :loop timeout /t 10 /nobreak >nul rundll32.exe user32.dll,LockWorkStation goto loop

Save this code in a file named lockscreen.bat.

When someone logs in and runs this script, it will wait for ten seconds and then lock the screen. It will repeat this process indefinitely.


    Now I did start working on this last Wednesday or Thursday again for the first time in months, but Doug was busy helping other students who had to take their certification exams. And otherwise he didn't wa t to help me because he wanted me to try. However, I was very tired from the gym. I am in Ketosis and I haven't resolved how to get enough electrolytes without sugar or carbs or artificial flavoring which does sometimes spike your insulin which would kick you out of ketosis. I tried pickle juice and was dissatisfied with this because it has to stay refrigerated and otherwise I didn't know if it was actually helping since I wasn't exactly drinking a whole jar of juice. So when I did my usual workout, I started to get sluggish and feel like I was about to slightly lose my balance and was really tired. And when I got to class, I couldn't think hardly at all. I ended up leaving class early which is very unusual for me. I think Doug must have taken from this that I did my best and couldn't figure it out. 

    However, I want to say that I did ask Doug a few days earlier why his scripts kept running even with the thumb drive pulled. He said, well, you're writing these scripts in batch, batch doesn't keep running by default in temp memory unless you pull a lot of strings to get it to do so. I asked him what he did to solve this problem and he said that he wrote his scripts in VBS. I asked why. I was surprised he told me because until now he was unwilling to divulge any of his secrets. I even asked him if he could furnish me with a list of the kinds of scripts he wrote and he said no because he wanted me to build up to more complicated ones and some he may never tell me. So he told me that he used VBS because it stays in memory even after the source is pulled. 

    I asked ChatGPT about this and found out that actually there's a number of languages that do this, not just VBS. I found that Python was one of them. Since my weather display is all in Python, I thought I would just go with that. I tried to convert everything in batch to python, this turned out to be quite a mess. I was already aware of the concept that spoken languages have words other languages don't. Likewise, things don't translate the same. In Brazilian Portuguese for example, back in the 1970s when my dad was there, guys would call attractive girls 'airplanes' in that language. This is sort of like the equivalent to calling an attractive girl a fox here in American English. You get why attractive girls would be called airplanes, but it's weird and if you translate it directly, it makes no sense because you're missing all of that context. 

    We have a similar problem when converting a batch script to python. First of all, python had to import utilities from the OS, it had it import time because of the ten second delay for caps lock and locking the screen, it had it import all sorts of things. Batch didn't have to do this. I asked Doug why. He said because a lot of those packages are pre-loaded into the system for Batch. 


    Monday 2024-07-15


    When I told Doug about my efforts trying to convert batch to python, and how there was a translation problem because direct translation causes problems, there's unnecessary code in the python version that actually doesn't apply in python but ChatGPT doesn't know this. So Doug asked me why I picked Python and I said well, I have been doing a lot of python stuff with the weather display, might as well stick with it and keep learning it. He told me he had bad news. What? Python doesn't come pre-installed in Windows. He asked me, do you remember when we started working on your weather display, we had to install it? Sort of I guess. Yeah. 

    The problem sank in slowly. Oh dear! Okay, so what can I do instead? Wait, ChatGPT said that there were a number of languages that do this thing where once activated, the scripts just run from memory and don't need the source script anymore. Doug then said, yeah but Windows only comes with batch and VBS pre-installed. Oh, so I have to do VBS. He said no, not necessarily. You can have the script load itself into memory. I said yeah but we already tried that and it didn't work. Why not just do VBS. He said well, the reason why I don't recommend you do VBS is because for all of these other languages such as batch, there's lots of documentation on how to use it. And VBS? There is not that much documentation on VBS. I said, yeah, but you were able to do it...without thinking about who I was talking to. Doug of all people. Guy can figure out anything! Tss. He said yeah, I did, but it was very, very, very hard. And it took a lot of time and tons of experimentation. I realized, yeah, so VBS is not a likely solution for me. But then he said he thought maybe he knew what was wrong with loading it into memory and how to fix it. 

    Doug and I were looking at the code. This is when Doug suddenly had a thought. He went to Stack Overflow and tried something from there that didn't work and then we ended up on another site https://ss64.com/nt/start.html, 'Start a program, command or batch script, opens in a new/separate command prompt window.' 

Syntax
      START "title" [/D path] [options] "command" [parameters]

Key:
   title       Text for the CMD window title bar (required.)
   path        Starting directory.
   command     The command, batch file or executable program to run.
   parameters  The parameters passed to the command.

Options:
   /MIN         Start window Minimized.
   /MAX         Start window Maximized.
   /W or /WAIT  Start application and wait for it to terminate.
                (see below)

   /LOW         Use IDLE priority class.
   /NORMAL      Use NORMAL priority class.
   /ABOVENORMAL Use ABOVENORMAL priority class.
   /BELOWNORMAL Use BELOWNORMAL priority class.
   /HIGH        Use HIGH priority class.
   /REALTIME    Use REALTIME priority class.
/B Start application without creating a new window. In this case Ctrl-C will be ignored - leaving Ctrl-Break as the only way to interrupt the application. /I Ignore any changes to the current environment, typically made with SET. Use the original environment passed to cmd.exe /NODE The preferred Non-Uniform Memory Architecture (NUMA) node as a decimal integer. /AFFINITY The processor affinity mask as a hexadecimal number. The process will be restricted to running on these processors. Options for running 16-bit Windows programs, on Windows 10 only: /SEPARATE Start in separate memory space. (more robust) 32 bit only. /SHARED Start in shared memory space. (default) 32 bit only.

Always include a TITLE this can be a simple string like "My Script" or just a pair of empty quotes ""
According to the Microsoft documentation, the title is optional, but depending on the other options chosen you can have problems if it is omitted.

If command is an internal cmd command or a batch file then the command processor CMD.exe is run with the /K switch. This means that the window will remain after the command has been run.

In a batch script, a START command without /wait will run the program and just continue, so a script containing nothing but a START command will close the CMD console and leave the new program running.

Document files can be invoked through their file association just by typing the name of the file as a command.
e.g. START "" MarchReport.DOC will launch the application associated with the .DOC file extension and load the document.

To minimise any chance of the wrong exectuable being run, specify the full path to command or at a minimum include the file extension: START "" notepad.exe

If you START an application without a file extension (for example WinWord instead of WinWord.exe)then the PATHEXT environment variable will be read to determine which file extensions to search for and in what order.
The default value for the PATHEXT variable is: .COM;.EXE;.BAT;.CMD

Start - run in parallel

The default behaviour of START is to instantiate a new process that runs in parallel with the main process. For arcane technical reasons, this does not work for some types of executable, in those cases the process will act as a blocker, pausing the main script until it’s complete.

In practice you just need to test it and see how it behaves.

Often you can work around this issue by creating a one line batch script (runme.cmd ) to launch the executable, and then call that script with START runme.cmd

Start /Wait

The /WAIT option should reverse the default 'run in parallel' behaviour of START but again your results will vary depending on the item being started, for example:

Echo Starting
START /wait "job1" calc.exe
Echo Done

The above will start the calculator and wait before continuing. However if you replace calc.exe with Winword.exe, to run Word instead, then the /wait will stop working, this is because Winword.exe is a stub which launches the main Word application and then exits.

A similar problem will occur when starting a batch file, by default START will run the equivalent of CMD /K which opens a second command window and leaves it open. In most cases you will want the batch script to complete and then just close its CMD console to resume the initial batch script. This can be done by explicitly running CMD /C ...

Echo Starting
START /wait "demojob" CMD /c demoscript.cmd
Echo Done

Add /B to have everything run in a single window.

In a batch file, an alternative is to use TIMEOUT to delay processing of individual commands.

START vs CALL

Starting a new process with CALL, is very similar to running START /wait, in both cases the calling script will (usually) pause until the second script has completed.

Starting a new process with CALL, will run in the same shell environment as the calling script. For a GUI application this makes no difference, but a second 'called' batch file will be able to change variables and pass those changes back to the caller.

In comparison START will instantiate a new CMD.exe shell for the called batch. This will inherit variables from the calling shell, but any variable changes will be discarded when the second script ends.

Run a program

To start a new program (not a batch script), you don’t have to use CALL or START, just enter the path/file to be executed, either on the command line or within a batch script. This will behave as follows:

  • On the command line, CMD.EXE does not wait for the application to terminate and control immediately returns to the command prompt.
  • Running a program from within a batch script, CMD.EXE will pause the initial script and wait for the application to terminate before continuing.
  • If you run one batch script from another without using either CALL or START, then the first script is terminated and the second one takes over.

Search order:

  • Running a program from CMD will search first in the current directory and then in the PATH.
  • Running a program from PowerShell will search first in the PATH and then in the current directory.
  • The Windows Run Line (win+r) will search first in App Paths [defined in HKLM\Software\Microsoft\Windows\CurrentVersion\App Paths] and then the PATH

Multiprocessor systems

Processor affinity is assigned as a hex number but calculated from the binary positions (similar to NODRIVES)

Hex Binary        Processors
 1 00000001 Proc 1 
 3 00000011 Proc 1+2
 7 00000111 Proc 1+2+3
 C 00001100 Proc 3+4 etc

Specifying /NODE allows processes to be created in a way that leverages memory locality on NUMA systems. For example, two processes that communicate with each other heavily through shared memory can be created to share the same preferred NUMA node in order to minimize memory latencies. They allocate memory from the same NUMA node when possible, and they are free to run on processors outside the specified node.

start /NODE 1 app1.exe
start /NODE 1 app2.exe

These two processes can be further constrained to run on specific processors within the same NUMA node.

In the following example, app1 runs on the low-order two processors of the node, while app2 runs on the next two processors of the node. This example assumes the specified node has at least four logical processors. Note that the node number can be changed to any valid node number for that computer without having to change the affinity mask.

start /NODE 1 /AFFINITY 0x3 app1.exe
start /NODE 1 /AFFINITY 0xc app2.exe

Running executable (.EXE) files

When a file that contains a .exe header, is invoked from a CMD prompt or batch file (with or without START), it will be opened as an executable file. The filename extension does not have to be .EXE. The file header of executable files start with the 'magic sequence' of ASCII characters 'MZ' (0x4D, 0x5A) The 'MZ' being the initials of Mark Zibowski, a Microsoft employee at the time the file format was designed.

Command Extensions

If Command Extensions are enabled, external command invocation through the command line or the START command changes as follows:

Non-executable files can be invoked through their file association just by typing the name of the file as a command. (e.g. WORD.DOC would launch the application associated with the .DOC file extension). This is based on the setting in HKCU\Software\Microsoft\Windows\CurrentVersion\Explorer\FileExts\.ext\OpenWithList, or if that is not specified, then the file associations - see ASSOC and FTYPE.

When executing a command line whose first token is the string CMD without an extension or path qualifier, then CMD is replaced with the value of the COMSPEC variable. This prevents picking up CMD.EXE from the current directory.

When executing a command line whose first token does NOT contain an extension, then CMD.EXE uses the value of the COMSPEC environment variable. This prevents picking up CMD.EXE from the current directory.

When executing a command line whose first token does NOT contain an extension, then CMD.EXE uses the value of the PATHEXT environment variable to determine which extensions to look for and in what order. The default value for the PATHEXT variable is: .COM;.EXE;.BAT;.CMD Notice the syntax is the same as the PATH variable, with semicolons separating the different elements.

When searching for an executable, if there is no match on any extension, then looks to see if the name matches a directory name. If it does, the START command launches the Explorer on that path. If done from the command line, it is the equivalent to doing a CD /D to that path.

Errorlevels

If the command is successfully started ERRORLEVEL =unchanged, typically this will be 0 but if a previous command set an errorlevel, that will be preserved (this is a bug).
If the command fails to start then ERRORLEVEL = 9059
START /WAIT batch_file - will return the ERRORLEVEL specified by EXIT

START is an internal command.

Examples

Start a program and wait for it to complete before continuing:

START "" /wait autocad.exe

Open a file with a particular program:

START "job1" "C:\Program Files\Microsoft Office\Winword.exe" "D:\Docs\demo.txt"

Run a minimised Login script:

CMD.exe /C START "Login Script" /Min CMD.exe /C Login.cmd

In this example the first CMD session will terminate almost immediately and the second will run minimised.

Open Windows Explorer and list the files in the current folder (.) :

C:\any\old\directory> START .

Open a webpage in the default browser, note the protocol is required (https://):

START https://ss64.com

Open a webpage in Microsoft Edge:

%windir%\explorer.exe microsoft-edge:https://ss64.com
or with a hard-coded path:
"C:\Program Files (x86)\Microsoft Edge\Application\msedge.exe" https://ss64.com

"%windir%\explorer.exe shell:Appsfolder\Microsoft.MicrosoftEdge_8wekyb3d8bbwe!MicrosoftEdge" https://ss64.com

Connect to a new printer: (this will setup the print connection/driver):

START \\print_server\printer_name

Start an application and specify where files will be saved (Working Directory):

START /D C:\Documents\ /MAX "Maximised Notes" notepad.exe

“Do not run; scorn running with thy heels” ~ Shakespeare, The Merchant of Venice

     Doug took from this one thing, which was that he needed to change the activation script from this:

start invis.vbs "%temp%\capslock.bat

    to

 start /D C:\ invis.vbs "%temp%\capslock.bat

     It now works like a charm. We activated it, we watched first to make sure it was working properly and that something wasn't broken, and then after caps lock had activated and deactivated once, then we pulled the drive and it kept going! 











This has been Truncat3d 00000000111100010100110______________end of line

2025-07-10 - BYU Wi‑Fi captive portal troubleshooting

  BYU Wi‑Fi Captive Portal Troubleshooting What happened I had used BYU Wi‑Fi just fine before, but at some point, the captive portal star...