473,513 Members | 2,595 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

SetComputerNameEx() Return Codes?

Hello all,

Having a problem with SetComputerNameEx() -- the API says it returns 0 on
failure, but for me it is always returning a random number on failure or
success. Interestingly though, the code is working in terms of renaming a
computer, assuming the new name is valid. How can i check to see if the
name is invalid, since the function is always returning a non-zero value?

Sample Code Below:

Private Sub RenameComputer(ByVal strNewName)

Dim RtrnVal

RtrnVal =
SetComputerNameEx(COMPUTER_NAME_FORMAT.ComputerNam ePhysicalDnsHostname,
strNewName)

MsgBox(RtrnVal)

If RtrnVal = 0 Then

MsgBox("Error: Could not rename computer. Check to make sure the computer
name does not contain spaces, symbols, or punctuation.")

myCaller.LblStatus.Text = "There was an error renaming the computer"

Else

myCaller.LblStatus.Text = "Computer renamed successfully. Please reboot to
continue."

myCaller.JoinDomainButton.Enabled = False

myCaller.DeptsBox.Enabled = False

End If

End Sub

Eric Dropps
Jr. Systems Administrator
Harvard University FAS Computer Services
dr****@fas.harvard.edu 617.495.9768

Sep 4 '07 #1
1 3039
Eric,
>How can i check to see if the
name is invalid, since the function is always returning a non-zero value?
You didn't post the most interesting part of your code - your
declaration of the function. But I'm guessing you've taken an old VB6
declaration where the return type is Long instead of Boolean as it
should be in VB.NET. That type of error generally manifests itself in
"random" number being returned (since you're reading garbage off the
stack).

>Sample Code Below:

Private Sub RenameComputer(ByVal strNewName)

Dim RtrnVal
Eek! I strongly recommend turning on Option Strict and start typing
your variables.
Mattias

--
Mattias Sjögren [C# MVP] mattias @ mvps.org
http://www.msjogren.net/dotnet/ | http://www.dotnetinterop.com
Please reply only to the newsgroup.
Sep 4 '07 #2

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

6
1889
by: Josh Mcfarlane | last post by:
I keep trying to get myself out of the return-code mindset, but it doesn't seem to work. They are suppose to get rid of if-then statements of return codes, but you still have to do an if statement...
16
3919
by: Fao, Sean | last post by:
As far as I can tell, the standard has defined three portable return codes from function main() (0, EXIT_SUCCESS, EXIT_FAILURE). Personally, on all platforms I have worked with, EXIT_SUCCESS is,...
3
2350
by: c# beginner | last post by:
we are trying to standardize return codes across our .NET applications (that are soon to be developed.) What is the best practice for standardizing return codes? I know of only the following...
10
15894
by: Tony | last post by:
I am running an application called AcroComm.exe to poll time clocks here at our company. I have written a small C# app that will poll the clocks based on information found in a DB. My problem is...
3
1458
by: RdS | last post by:
Where do I find return codes for MS methods. For instance the filesystemobject methods. I need to know what methods return (error codes, etc. and what they mean). I have searched MSDN and of...
24
2159
by: Earl | last post by:
I have all of my data operations in a separate library, so I'm looking for what might be termed "best practices" on a return type from those classes. For example, let's say I send an update from...
3
55644
by: asearle | last post by:
Hallo everyone, I have a perl script which can return error codes. I have done this with, for example, 'exit 11;', which would (I imagine) send the exit code 11 (instead of 0) back to the calling...
8
1711
by: sloan | last post by:
Does anyone have any good articles on Exception Handing in DotNet. As a "get rid of the API mode of knowing if something worked, we're not in VB6 land anymore Dorothy". I have a few people at...
13
2540
by: mike3 | last post by:
Hi. (crossposted because the program is in C++ and some C++-related elements are discussed, hence comp.lang.c++, plus general program design questions are asked, hence comp.programming.) I'm...
0
7260
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
7384
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
7537
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...
0
7525
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
3233
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...
0
3222
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
1594
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...
1
799
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
456
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence...

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.