By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
459,182 Members | 1,135 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 459,182 IT Pros & Developers. It's quick & easy.

inconsistent results with different methods of executing file

P: n/a
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\ActiveComputer Name",
"ComputerName", AssetID, Microsoft.Win32.RegistryValueKind.String)
My.Computer.Registry.SetValue("HKEY_CURRENT_USER\V olatile
Environment", "LOGONSERVER", "\\" & AssetID,
Microsoft.Win32.RegistryValueKind.String)
My.Computer.Registry.SetValue("HKEY_CURRENT_USER\S oftware
\Microsoft\Windows\ShellNoRoam", "(Default)", AssetID,
Microsoft.Win32.RegistryValueKind.String)

'creates bat file deletes the exe and itself
My.Computer.FileSystem.WriteAllText("killMyself.ba t",
vbCrLf & "del assetid.txt" & vbCrLf, False)
My.Computer.FileSystem.WriteAllText("killMyself.ba t", "del
rename.exe" & vbCrLf, True)
My.Computer.FileSystem.WriteAllText("killMyself.ba t", "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.
Jun 27 '08 #1
Share this Question
Share on Google+
7 Replies


P: n/a

"mark" <ma******@gmail.comwrote in message news:26**********************************@y38g2000 hsy.googlegroups.com...
>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.

--
Mike
Microsoft Visual Basic MVP

Jun 27 '08 #2

P: n/a
MikeD wrote:
> '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.
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.
--
..NET: It's About Trust!
http://vfred.mvps.org
Jun 27 '08 #3

P: n/a

"Karl E. Peterson" <ka**@mvps.orgwrote in message
news:uM**************@TK2MSFTNGP03.phx.gbl...
>
>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.
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.

--
Mike
Microsoft MVP Visual Basic
Jun 27 '08 #4

P: n/a
MikeD wrote:
"Karl E. Peterson" <ka**@mvps.orgwrote ...
>>
>>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.

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>
--
..NET: It's About Trust!
http://vfred.mvps.org
Jun 27 '08 #5

P: n/a

"MikeD" <no****@nowhere.eduwrote in message
news:OV**************@TK2MSFTNGP04.phx.gbl...
>
"Karl E. Peterson" <ka**@mvps.orgwrote in message
news:uM**************@TK2MSFTNGP03.phx.gbl...
>>
>>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.

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.

Jun 27 '08 #6

P: n/a
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.
Jun 27 '08 #7

P: n/a
mark wrote:
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\Run Once
key. This will, of course, require admin privs.
--
..NET: It's About Trust!
http://vfred.mvps.org
Jun 27 '08 #8

This discussion thread is closed

Replies have been disabled for this discussion.