inconsistent results with different methods of executing file

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.
 
M

MikeD

mark said:
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)

First of all, you need to ask this in a .NET newsgroup.

Second of all, there is NO WAY IN HELL (at least IMO) you should be doing this.
 
K

Karl E. Peterson

MikeD said:
First of all, you need to ask this in a .NET newsgroup.

Agreed. m.p.vb.* has no place in this discussion.
Second of all, there is NO WAY IN HELL (at least IMO) you should be doing this.

But why this? Looks like a fairly common IT Dept type (make-work) exercise.
 
M

MikeD

Karl E. Peterson said:
But why this? Looks like a fairly common IT Dept type (make-work)
exercise.

It's just the way he's going about it. Sure, I can *possibly* see an IT
need to change the computer name, but not the way Mark's describing it be
done...a program in the startup folder which then deletes itself. That just
sounds too....suspicious.
 
K

Karl E. Peterson

MikeD said:
It's just the way he's going about it. Sure, I can *possibly* see an IT
need to change the computer name, but not the way Mark's describing it be
done...a program in the startup folder which then deletes itself. That just
sounds too....suspicious.

Yeah, but IT depts aren't known to hire the brightest bulbs in the closet.

Okay, ya got me. <g>
 
B

Bill McCarthy

MikeD said:
It's just the way he's going about it. Sure, I can *possibly* see an IT
need to change the computer name, but not the way Mark's describing it be
done...a program in the startup folder which then deletes itself. That
just sounds too....suspicious.

Right. The correct way to do this would be to add an entry to the registry's
RunOnce section.
 
M

mark

Ok, yes I am in an IT dept., I am also new, and I am also new to VB.
Editing the registry directly probably isn't the best way but its
worked to far and i haven't run into any problems. As far as it being
in the startup folder and deleting itself, it probably does look a
little suspicious, and i can't really think of a way to convince you
that it isn't a virus, so you'll just have to trust me, although i am
definitely open to suggestions. Were making an drive image and this
program would go onto it and that would just automate the process of
naming the computers that the image goes on to.
 
K

Karl E. Peterson

mark said:
Ok, yes I am in an IT dept., I am also new, and I am also new to VB.
Editing the registry directly probably isn't the best way but its
worked to far and i haven't run into any problems. As far as it being
in the startup folder and deleting itself, it probably does look a
little suspicious, and i can't really think of a way to convince you
that it isn't a virus, so you'll just have to trust me, although i am
definitely open to suggestions. Were making an drive image and this
program would go onto it and that would just automate the process of
naming the computers that the image goes on to.

Since you're familiar with the registry, take Bill's advice and stick the execution
reference to this app in the HKLM\Software\Microsoft\Windows\CurrentVersion\RunOnce
key. This will, of course, require admin privs.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top