M
mark
I am writing a program that will be placed in the startup folder so
that on login it executes, it also needs to delete itself so it
creates a batch file which cleans up. After that it restarts the
computer so the changes take effect, the changes i refer to being that
it renames the computer.
When testing the program, it runs fine and does its job and initiates
the restart (30 second countdown). In that 30 seconds, i look into to
startup folder and see that the exe itself is still there, although
the batch file has deleted a txt file(that was generated during the
program) and itself. I abort the restart from the command line.
Now if i run the program manually it works fine and deletes itself. I
can not figure out the difference between the computer running it
automatically and my initiating it myself, and why that would cause it
to not be deleted.
Here is the last bit of code that deals with the batch file and
restart:
Else
'selects first part of asset ID (before the comma)
AssetID = AssetID.Substring(0, 15)
'changes registry value
My.Computer.Registry.SetValue("HKEY_LOCAL_MACHINE\SYSTEM
\ControlSet001\Control\ComputerName\ComputerName", "ComputerName",
AssetID, Microsoft.Win32.RegistryValueKind.String)
My.Computer.Registry.SetValue("HKEY_LOCAL_MACHINE\SYSTEM
\CurrentControlSet\Services\Tcpip\Parameters", "Hostname", AssetID,
Microsoft.Win32.RegistryValueKind.String)
My.Computer.Registry.SetValue("HKEY_LOCAL_MACHINE\SYSTEM
\CurrentControlSet\Services\Tcpip\Parameters", "NV Hostname", AssetID,
Microsoft.Win32.RegistryValueKind.String)
My.Computer.Registry.SetValue("HKEY_LOCAL_MACHINE\SYSTEM
\ControlSet001\Control\ComputerName", "ComputerName", AssetID,
Microsoft.Win32.RegistryValueKind.String)
My.Computer.Registry.SetValue("HKEY_LOCAL_MACHINE\SYSTEM
\ControlSet001\Control\ComputerName\ActiveComputerName",
"ComputerName", AssetID, Microsoft.Win32.RegistryValueKind.String)
My.Computer.Registry.SetValue("HKEY_CURRENT_USER\Volatile
Environment", "LOGONSERVER", "\\" & AssetID,
Microsoft.Win32.RegistryValueKind.String)
My.Computer.Registry.SetValue("HKEY_CURRENT_USER\Software
\Microsoft\Windows\ShellNoRoam", "(Default)", AssetID,
Microsoft.Win32.RegistryValueKind.String)
'creates bat file deletes the exe and itself
My.Computer.FileSystem.WriteAllText("killMyself.bat",
vbCrLf & "del assetid.txt" & vbCrLf, False)
My.Computer.FileSystem.WriteAllText("killMyself.bat", "del
rename.exe" & vbCrLf, True)
My.Computer.FileSystem.WriteAllText("killMyself.bat", "del
killMyself.bat", True)
'shuts down computer (-s to shutdown, -r to restart)(-t 5
sets a 5 second delay to restart)
Shell("shutdown.exe -r")
End If
'executes delete file, should run before shutdown completes
Shell("killMyself.bat")
End Sub
End Module
Any help would be appreciated, thanks.
that on login it executes, it also needs to delete itself so it
creates a batch file which cleans up. After that it restarts the
computer so the changes take effect, the changes i refer to being that
it renames the computer.
When testing the program, it runs fine and does its job and initiates
the restart (30 second countdown). In that 30 seconds, i look into to
startup folder and see that the exe itself is still there, although
the batch file has deleted a txt file(that was generated during the
program) and itself. I abort the restart from the command line.
Now if i run the program manually it works fine and deletes itself. I
can not figure out the difference between the computer running it
automatically and my initiating it myself, and why that would cause it
to not be deleted.
Here is the last bit of code that deals with the batch file and
restart:
Else
'selects first part of asset ID (before the comma)
AssetID = AssetID.Substring(0, 15)
'changes registry value
My.Computer.Registry.SetValue("HKEY_LOCAL_MACHINE\SYSTEM
\ControlSet001\Control\ComputerName\ComputerName", "ComputerName",
AssetID, Microsoft.Win32.RegistryValueKind.String)
My.Computer.Registry.SetValue("HKEY_LOCAL_MACHINE\SYSTEM
\CurrentControlSet\Services\Tcpip\Parameters", "Hostname", AssetID,
Microsoft.Win32.RegistryValueKind.String)
My.Computer.Registry.SetValue("HKEY_LOCAL_MACHINE\SYSTEM
\CurrentControlSet\Services\Tcpip\Parameters", "NV Hostname", AssetID,
Microsoft.Win32.RegistryValueKind.String)
My.Computer.Registry.SetValue("HKEY_LOCAL_MACHINE\SYSTEM
\ControlSet001\Control\ComputerName", "ComputerName", AssetID,
Microsoft.Win32.RegistryValueKind.String)
My.Computer.Registry.SetValue("HKEY_LOCAL_MACHINE\SYSTEM
\ControlSet001\Control\ComputerName\ActiveComputerName",
"ComputerName", AssetID, Microsoft.Win32.RegistryValueKind.String)
My.Computer.Registry.SetValue("HKEY_CURRENT_USER\Volatile
Environment", "LOGONSERVER", "\\" & AssetID,
Microsoft.Win32.RegistryValueKind.String)
My.Computer.Registry.SetValue("HKEY_CURRENT_USER\Software
\Microsoft\Windows\ShellNoRoam", "(Default)", AssetID,
Microsoft.Win32.RegistryValueKind.String)
'creates bat file deletes the exe and itself
My.Computer.FileSystem.WriteAllText("killMyself.bat",
vbCrLf & "del assetid.txt" & vbCrLf, False)
My.Computer.FileSystem.WriteAllText("killMyself.bat", "del
rename.exe" & vbCrLf, True)
My.Computer.FileSystem.WriteAllText("killMyself.bat", "del
killMyself.bat", True)
'shuts down computer (-s to shutdown, -r to restart)(-t 5
sets a 5 second delay to restart)
Shell("shutdown.exe -r")
End If
'executes delete file, should run before shutdown completes
Shell("killMyself.bat")
End Sub
End Module
Any help would be appreciated, thanks.