473,387 Members | 1,766 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,387 software developers and data experts.

inconsistent results with different methods of executing file

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
7 1144

"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
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

"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
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

"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
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
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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
by: Denis S. Otkidach | last post by:
I've noticed that the order of attribute lookup is inconsistent when descriptor is used. property instance takes precedence of instance attributes: >>> class A(object): .... def...
2
by: Edvard Majakari | last post by:
Hi all ya unit-testing experts there :) Code I'm working on has to parse large and complex files and detect equally complex and large amount of errors before the contents of the file is fed to...
3
by: John C Kirk | last post by:
I've come across an odd situation, where doing a floating point division produces different results for the same numbers. Basically, there are 4 ways to run this application: A) Debug build,...
10
by: Robert Baer | last post by:
<SWM.HTM listing; does not work; positioning wrong (below main GIF)> <!-- IE adds a horizontal 4-icon strip near the upper left corner when that area is visited (WTF?) --> <head> <meta...
2
by: Prophet | last post by:
Can someone help me troubleshoot this IISSTATE log ? I have tried to make sense out of it but with no luck I am currently running IIS5 on a Win 2k box. Hosting 3 web sites and runnning asp...
20
by: Francine.Neary | last post by:
I am learning C, having fun with strings & pointers at the moment! The following program is my solution to an exercise to take an input, strip the first word, and output the rest. It works fine...
1
by: catudalg | last post by:
Configuration: Windows 2000 sp3 MS Access 2000 (9.0.4402 SR-1) Visual Foxpro 9.0 detached tables MS VFP Driver 6.01.6830.01 06/19/2003 For example, a simple query like: select * from ddwg1...
5
by: Gerardo Herzig | last post by:
Hi all. Im in this situation: I want to perform several kind of (validating) methods to a given value. Lets say i have a class named Number, and the following methods: is_really_a_number(),...
1
by: rnhuch | last post by:
My platform is SQL Server 2005. One of the tables of my db has 28589928 rows and one of the fields is real. When I backup and restore this database to another server (using the SQL Server internal...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.