View Full Version : Error 30 from call to OS_GetComputerName
EmbeddedMan
21-02-2021, 22:57
On one of my user's computers, they get the following error when they run my code:
Main Script Name : C:UsersxxDownloadsFirmware_v270_WinEBBUpgraderGUI_v270.exe
Error code 30
Line number 26
Token found OS_GETCOMPUTERNAME
This occurs on the following line (line 26)
Global ComputerName As String Value OS_GetComputerName
This program has run fine on thousands of different computers. Any idea what "Error code 30" is and what could cause OS_GetComputerName to fail this way?
Thanks much-
*Brian
DirectuX
21-02-2021, 23:33
Hi Brian,
maybe knowing what system (real windows : which version ?, virtualization, wine...) is the program running on would be of some help.
Also the computer name ( = expected name ?)
Regards
EmbeddedMan
21-02-2021, 23:38
Sure, I'll provide what I know.
The computer system where the error is generated is Windows 10. I do know if it is up to date or not.
I don't think it's being virtualized, although I can try to contact the user and ask.
I don't know what the expected "Computer Name" is for their machine. What can I ask them to do to provide this information? Is there an easy way of reading out the "Computer Name" value that will normally be returned by the OS_GetComputerName call?
*Brian
DirectuX
21-02-2021, 23:41
Maybe this MS link (https://support.microsoft.com/en-us/office/do-you-need-help-locating-your-computer-name-00384381-8aa9-4398-b81b-475f09fed618) can help you display the computer name, it's in the system panel.
Sure, I'll provide what I know.
The computer system where the error is generated is Windows 10. I do know if it is up to date or not.
I don't think it's being virtualized, although I can try to contact the user and ask.
I don't know what the expected "Computer Name" is for their machine. What can I ask them to do to provide this information? Is there an easy way of reading out the "Computer Name" value that will normally be returned by the OS_GetComputerName call?
*Brian
Petr Schreiber
22-02-2021, 20:20
Brian,
can your user try this script on his PC, will it improve the situation?
dword bufferSize = 1024
dim buffer as asciiz * bufferSize
DECLARE FUNCTION GetComputerName IMPORT "KERNEL32.DLL" ALIAS "GetComputerNameW" (BYREF lpBuffer AS ASCIIZ, BYREF nSize AS DWORD) AS LONG
GetComputerName(buffer, bufferSize)
msgbox 0, buffer
Petr
EmbeddedMan
22-02-2021, 20:36
Thanks - I'll build a new version of the app for them to try with that change and let you know how it goes. Thanks!!
*Brian
ReneMiner
25-02-2021, 01:02
this for Error 30
ERROR_READ_FAULT
30 (0x1E)
The system cannot read from the specified device.
and this for the next time
https://docs.microsoft.com/en-us/windows/win32/debug/system-error-codes--0-499-
EmbeddedMan
25-02-2021, 01:10
this for Error 30
and this for the next time
https://docs.microsoft.com/en-us/windows/win32/debug/system-error-codes--0-499-
Fair enough, but what about the actual function call could return that error? The error itself doesn't give me any ideas on what I can ask my user to check in order to solve the problem.
*Brian
ReneMiner
27-02-2021, 06:54
i would suspect the script usually is started by some link thats properties say to run it as administrator. the original link that you created once was moved accidentally and someone made a new link to replace the missing one but didn't know the "Run as administrator" has to be checked ;)
anyway, if your script is running from *.tBasic or *.tBasicC source through thincore (thinBasic.exe) or from bundled *.exe directly
you will find out if you right click the link that starts it on the "suspicious reacting engine" and check the properties.
for permanent solution follow the steps on the attached image where i suppose your script is running via thinCore from script source.
If running from bundled exe it would be the exe-file then thats properties are to open in explorer and where you set "run as admin" for compatibility reasons...
If it works, you might consider a script solution to be executed on all engines that makes either the bundled exe or *.tBasic-files run as admin always.
if running from *.tBasic*-script-sources -and not to bother of different file extensions if crypted or special console files - i would suggest to run thinBasic.exe with elevated privileges always. Because its not possible to set for all users in one go (security feature of windows prevents to set administrator priviliges simply to HKEY_LOCAL_MACHINE ) you have to set it at least twice per computer.
In any case to all existing users accounts and once to the .Default-users account - so in future every new account will inherit the setting. since only HKEY_USERS and HKEY_LOCAL_MACHINE can be accessed remotely but HKL_MACHINE will not accept generalized to run as admin always - as mentioned above -
it were the most simple solution to inform all users via net broadcast to import a registry settings file - requires the same file locations on all machines.
optional the thinbasic-script that creates the .reg-file can be run on every pc to provide the correct App_Path.
'---Script created on 02-27-2021 04:52:37 by Me
' ### RegTBAsAdmin.tBasic ###
' this script will create 2 files:
'- TbRunAsAdmin.reg
'- Tb2RegImpAdmin.BAT
' goal: run thinBasic-scripts with elevated privileges
' usually it will succeed importing the regfile from thinbasic-script
' alternate option : create bundled exe of this that will run on each pc on your
' network (right-click + RunAs Admin)
' another option : if thinBasic-path or the optional other files are equal on all
' pcs you can use "Reg Import TbRunAsAdmin.reg" on elevated command prompt
string sRegFile = App_Scriptpath & "TbRunAsAdmin.REG"
string sBatFile = App_Scriptpath & "Tb2RegImpAdmin.BAT"
' BACKSLASHES: \ in reg value name and in reg_[.]*sz data
' must be escaped with a backslash and become: \\
' DOUBLE QUOTES: " within quoted strings will become: \"
string TBPath$ = replace$(App_path, "\", "!") ' do the backslash-thing
TBPath$ = replace$(TBPath$, "!","\\")
string sCode = "Windows Registry Editor Version 5.00" & crlf & crlf
long turn
repeat
incr turn
sCode &= "[HKEY_" & choose$(turn,"CURRENT_USER", "USERS\.DEFAULT")
sCode &= "\Software\Microsoft\Windows NT\CurrentVersion\AppCompatFlags\Layers]" & crlf
' -- run tBasic-scripts as admin through permanently elevating thincore:
sCode &= $DQ & TBPath$ & "thinBasic.exe" & $DQ & "=" & $DQ & " ~RUNASADMIN" & $DQ & crlf
' -- if users have access to thinAir uncomment the next line to allow saving anywhere:
'sCode &= $DQ & TBPath$ & "thinAir\\thinAir.exe" & $DQ & "=" & $DQ & " ~RUNASADMIN" & $DQ & crlf
' -- maybe some bundled exe that shall be executed as admin?
' -- is it located at the same address network-wide?
'sCode &= $DQ & "\\\\yourdomain\\network_location\\SharedFile.exe" & $DQ & "=" & $DQ & " ~RUNASADMIN" & $DQ & crlf
' -- or locally stored to all clients?:
'sCode &= $DQ & "C:\\yourPath\\LocalFile.exe" & $DQ & "=" & $DQ & " ~RUNASADMIN" & $DQ & crlf
sCode &= crlf
until turn = 2
sCode &= string$(2, $spc)
' almost ready... registry uses UCS2-Le encoding,
' 16 Bit with Byte-Order-Mark (BOM) = FF FE
' sCode is plain ascii until here - lets convert!
long nChars = lenf(sCode)
' allocate destination memory for Ucs2_Le:
' 2 Bytes BOM, 2 bytes per char
string AsUcs2_Le = mkbyt$(0xFF, 0xFE) & _ ' = BOM
repeat$(nChars,mkbyt$(0x20, 0x00))
' just using count of 8 bit chars for 16-bit space-chars
'-- a virtual byte at the current - first - char of sCode to read it:
dim bRead as Byte at strptr(sCode)
' get position of the first char in destinations memory
dword pos2Write = strptr(AsUcs2_Le)+2
while nChars
poke( byte, pos2Write, bRead )
' 1 char less to do:
decr nChars
' move the byte to read onto the next char:
SetAt(bRead, GetAt(bRead) + 1)
' go 2 bytes (skip 1 + go 1) forward at destination memory
pos2Write += 2
wend
' all converted, now save it to a REG-file next to this script
Save_File( sRegFile, AsUcs2_Le)
AsUcs2_Le = Shell_CaptureOutput( "REG IMPORT " & $DQ & sRegFile & $DQ, "", %sw_Hide, 1500) & crlf
save_File( sBatFile, "Reg Import " & $DQ & sRegFile & $DQ & crlf & string$(3,$spc) )
if msgbox(AsUcs2_Le & "Is the result bad enough to try something else?", %MB_YesNo, "registry replies:") = %IDNO Then
msgbox ("Anyway you can run regedit as administrator and import" & crlf & sRegFile, %MB_IconInformation | %MB_OK, "Keep in mind:")
AsUcs2_Le ="..."
EndIf
EmbeddedMan
27-02-2021, 15:45
Thanks for the detailed suggestion.
We distribute this application via bundled .exe. The user does not have a shortcut or lnk file. They simply double click on the .exe. (The user has no idea that this .exe was made with ThinBasic.)
I'm struggling a little bit to understand why administrator privileges would be required to get the ComputerName on just this one machine (out of many which run our .exe without admin).
If running as admin does fix the problem, we would have to weigh this solution being fixed for one user compared to causing a lot of calls to customer support by people who are surprised that running our little updater app is asking them for admin privileges. That would likely generate a lot of extra worry in our users.
Thanks again-
DirectuX
28-02-2021, 11:25
Hi Brian,
did you already check if there is something special, uncommon, in the computer name (no name at all or foreign chars...) and in the way your app is launched (virtualization, os, path...) ?
Because if it worked anywhere before, the problem is unlikely in your code.
Regards.
EmbeddedMan
28-02-2021, 17:36
We were able to get the user to send us this:
10251
Looks like a pretty normal computer name of "Home-1".
I tried setting my computer's name to "Home-1" and could not reproduce the problem.
As far as the way the app is launched - they download a zip file of the .exe (bundled) application, unzip it, then double click on the .exe to run the app. It is not being run in a virtualized environment.
It has never worked before on this user's machine, but has worked on many other user's machines.
Clearly there is something 'different' with this user's machine, but they are non-technical and it will be up to us to hold their hand to figure out what it is. So far we don't even have any ideas on what to ask them to check for.
THanks for all your help everybody -
*Brian
DirectuX
28-02-2021, 21:21
On the provided screenshot, it looks like there's a space char before the "1"
Looks like a pretty normal computer name of "Home-1".
I tried setting my computer's name to "Home-1" and could not reproduce the problem.
EmbeddedMan
28-02-2021, 22:27
I'm unable to test that because spaces aren't allowed as part of the Computer Name. So Windows won't let me rename my computer to a name which includes a space.
If this user did name their computer a name with a space somehow, they didn't use the normal "Rename your PC" method.
DirectuX
01-03-2021, 18:56
You may not, but the user is
able to rename it without a space.
I'm unable to test that because spaces aren't allowed as part of the Computer Name. So Windows won't let me rename my computer to a name which includes a space.
If this user did name their computer a name with a space somehow, they didn't use the normal "Rename your PC" method.
EmbeddedMan
01-03-2021, 19:57
You may not, but the user is
able to rename it without a space.
Very good point. We will suggest that to them if they continue to have issues.
Thanks for the suggestion.
*Brian
ErosOlmi
02-03-2021, 22:24
Hi Brian,
I'm not sure error occurs due to OS_GetComputerName function.
Maybe parser is not able to exactly determine the precise line/byte where error occurs.
Or maybe some char of the computer name is a wide char (unicode)
Can you create simple a script that does something like the following and see if it is working or not in the computer having problems:
USES "OS"
Global sComputerName As String Value OS_GetComputerName
MsgBox sComputerName
Thanks
Eros
EmbeddedMan
03-03-2021, 01:34
Hi Brian,
I'm not sure error occurs due to OS_GetComputerName function.
Maybe parser is not able to exactly determine the precise line/byte where error occurs.
Or maybe some char of the computer name is a wide char (unicode)
Can you create simple a script that does something like the following and see if it is working or not in the computer having problems:
USES "OS"
Global sComputerName As String Value OS_GetComputerName
MsgBox sComputerName
Thanks
Eros
Eros, thanks for the suggestion. Here is the first part of my application code:
Uses "UI"
Uses "CONSOLE"
Uses "COMM"
Uses "WMI"
Uses "OS"
'---Constant declarations
Begin ControlID
%ID_StartUpdateButton
%ID_ExitButton
%ID_CommandOutputTexBox
%IDC_TIMER
End ControlID
%TIMER_DELAY = 100 '---Timer delay (in milliseconds, not very accurate below about 100)
Global hComm As Long
Global nBytes As Long
Global sBuffer As String
Global gPortOpen As Boolean
Global pID As Number
Global vData() As String
Global nItems As Long
Global Counter As Long
Global Position As Long
Global ComputerName As String Value OS_GetComputerName
Global Ports() As String
Global CountATI As Long
Global sHexFilename As String
Global sFirmwareNumber As String
Global bConsole As Boolean
Global bUpdaterConsole As Boolean
Global sCommandLine As String
' Replace the filename in the next two lines to change which HEX file gets programmed
#BUNDLE File "HEX", ".\EBF_v270.hex", "", ReplaceExisting=1
sFirmwareNumber = "2.7.0"
We have already sent this user several different things to try, in order to help us diagnose the problem and try some workarounds, and we haven't received any word back. We're hoping this is a good sign - that one of the things we asked them to try actually worked. (Normally you don't get any support contacts from things that work, only things that don't work, as I'm sure you're well aware.) We're not really able to push harder on them to try more tests at this point.
If they come back and want to try more things, I'll make an .exe and get them to test with your idea.
Until then, we can hope the issue has resolved itself.
Again, thanks, everyone on this forum is so helpful.