Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsFree MagazinesWhite PapersSubmit Content
Discussion GroupsASP.NETWindows FormsLanguages.NET FrameworkVisual Studio.NET
Articles.NET FrameworkASP.NETToolsWindows Forms
.NET DirectoryOpen Source ProjectsUser GroupsWeb Resources
Related Topics
Visual Basic 6SQL ServerMS AccessOther DB ProductsMS Server ProductsMore Topics ...

.NET Forum / Languages / VB.NET / May 2008

Tip: Looking for answers? Try searching our database.

inconsistent results with different methods of executing file

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
mark - 28 May 2008 18:40 GMT
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.
MikeD - 28 May 2008 19:49 GMT
>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
[quoted text clipped - 24 lines]
> \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.

Signature

Mike
Microsoft Visual Basic MVP

Karl E. Peterson - 28 May 2008 20:31 GMT
>>            'selects first part of asset ID (before the comma)
>>            AssetID = AssetID.Substring(0, 15)
[quoted text clipped - 5 lines]
>
> 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.
Signature

.NET: It's About Trust!
http://vfred.mvps.org

MikeD - 28 May 2008 22:38 GMT
>> 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.

Signature

Mike
Microsoft MVP Visual Basic

Karl E. Peterson - 28 May 2008 23:57 GMT
>>> Second of all, there is NO WAY IN HELL (at least IMO) you should be doing
>>> this.
[quoted text clipped - 6 lines]
> 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>
Signature

.NET: It's About Trust!
http://vfred.mvps.org

Bill McCarthy - 29 May 2008 03:31 GMT
>>> Second of all, there is NO WAY IN HELL (at least IMO) you should be
>>> doing this.
[quoted text clipped - 6 lines]
> 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.
mark - 29 May 2008 14:15 GMT
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.
Karl E. Peterson - 29 May 2008 23:11 GMT
> 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
[quoted text clipped - 5 lines]
> 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.
Signature

.NET: It's About Trust!
http://vfred.mvps.org


Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.