Vb2012 admin permission - vb.net

I have coded up a cleaner type of program but getting a huge error with permissions ( I think )
The error message is printed out like so.
An unhandled exception of type 'System.UnauthorizedAccessException' occurred in mscorlib.dll
Additional information: Access to the path 'C:\Windows\CSC\v2.0.6' is denied.
And it says that the error part of the code is this line
For Each fi In DirectroyInfos.GetFiles(filter)
But here is the fill block of code.
For Each fi In DirectroyInfos.GetFiles(filter)
Try
file_count = file_count + 1
file_size = CULng(file_size + fi.Length)
FilesToDelete.Add(fi.FullName)
Catch ex As UnauthorizedAccessException
'There's really no pretty way to handle this exception
Catch ex As FileNotFoundException
'There's really no pretty way to handle this exception
End Try
I think it's some sort of permission problem I have windows 7 and have noticed there are a lot of run has admin problems.. I think its trying to remove or gain access to a file which it does not have permission to get .
Is there anyway to fix this? Am I missing something in my coding?

As you said in your question, you don't have write access that file.
Either skip files you don't have access to, or run the application as admin.

There appears to be a limitiation with the win32 api that will skip all files in the folder if you do not have access to one of them.
Check out this solution from Microsoft Connect:
How to: Iterate Through a Directory Tree (C# Programming Guide)

Related

Python: If error occurs anywhere, do specific line of code

I have a script I'm trying to write to process a large amount of data. There are, of course, potential for errors. In the script I need to connect to databases. If the script encounters an error, the code never reaches the point where the connection to the database is terminated. I'd like to have something in my python code that will recognize an error occurs, not matter where, and if nothing else at least close those databases. Does something like this exist? I know I can use try/except, but that would only work if I know exactly where I could get the error? I'm basically looking for a catchall to close my databases in the event an error occurs in a location I didn't anticipate.
To run certain cleanup code even if there is an error, use the finally block:
try:
# do stuff, possible exception
except:
# run this if exception
finally:
# always run this, even if exception
Reference: https://docs.python.org/3/tutorial/errors.html#defining-clean-up-actions

WebSphere wsadmin testConnection error message

I'm trying to write a script to test all DataSources of a WebSphere Cell/Node/Cluster. While this is possible from the Admin Console a script is better for certain audiences.
So I found the following article from IBM https://www.ibm.com/support/knowledgecenter/en/SSAW57_8.5.5/com.ibm.websphere.nd.multiplatform.doc/ae/txml_testconnection.html which looks promising as it describles exactly what I need.
After having a basic script like:
ds_ids = AdminConfig.list("DataSource").splitlines()
for ds_id in ds_ids:
AdminControl.testConnection(ds_id)
I experienced some undocumented behavior. Contrary to the article above the testConnection function does not always return a String, but may also throw a exception.
So I simply use a try-catch block:
try:
AdminControl.testConnection(ds_id)
except: # it actually is a com.ibm.ws.scripting.ScriptingException
exc_type, exc_value, exc_traceback = sys.exc_info()
now when I print the exc_value this is what one gets:
com.ibm.ws.scripting.ScriptingException: com.ibm.websphere.management.exception.AdminException: javax.management.MBeanException: Exception thrown in RequiredModelMBean while trying to invoke operation testConnection
Now this error message is always the same no matter what's wrong. I tested authentication errors, missing WebSphere Variables and missing driver classes.
While the Admin Console prints reasonable messages, the script keeps printing the same meaningless message.
The very weird thing is, as long as I don't catch the exception and the script just exits by error, a descriptive error message is shown.
Accessing the Java-Exceptions cause exc_value.getCause() gives None.
I've also had a look at the DataSource MBeans, but as they only exist if the servers are started, I quickly gave up on them.
I hope someone knows how to access the error messages I see when not catching the Exception.
thanks in advance
After all the research and testing AdminControl seems to be nothing more than a convinience facade to some of the commonly used MBeans.
So I tried issuing the Test Connection Service (like in the java example here https://www.ibm.com/support/knowledgecenter/en/SSEQTP_8.5.5/com.ibm.websphere.base.doc/ae/cdat_testcon.html
) directly:
ds_id = AdminConfig.list("DataSource").splitlines()[0]
# other queries may be 'process=server1' or 'process=dmgr'
ds_cfg_helpers = __wat.AdminControl.queryNames("WebSphere:process=nodeagent,type=DataSourceCfgHelper,*").splitlines()
try:
# invoke MBean method directly
warning_cnt = __wat.AdminControl.invoke(ds_cfg_helpers[0], "testConnection", ds_id)
if warning_cnt == "0":
print = "success"
else:
print "%s warning(s)" % warning_cnt
except ScriptingException as exc:
# get to the root of all evil ignoring exception wrappers
exc_cause = exc
while exc_cause.getCause():
exc_cause = exc_cause.getCause()
print exc_cause
This works the way I hoped for. The downside is that the code gets much more complicated if one needs to test DataSources that are defined on all kinds of scopes (Cell/Node/Cluster/Server/Application).
I don't need this so I left it out, but I still hope the example is useful to others too.

MQQueueManager Constructor throwing FileNotFoundException

I have the following vb.net code:
Imports IBM.WMQ
[...]
MQEnvironment.Hostname = hostName
MQEnvironment.Port = portNumber
MQEnvironment.Channel = channelName
queueManager = New MQQueueManager(queueManagerName) ' error here
which is throwing the following error:
System.IO.FileNotFoundException occurred
FileName=C:\Users\User\Documents\Visual Studio 2012\Projects\[...]\bin\Debug\mqclient.ini
HResult=-2147024894
Message=Could not find file 'C:\Users\User\Documents\Visual Studio 2012\Projects\[...]\bin\Debug\mqclient.ini'.
Source=mscorlib
StackTrace:
at System.IO.__Error.WinIOError(Int32 errorCode, String maybeFullPath)
I am not using any ini files in the construction of my queue manager, so does anyone have any idea what's going on - why is it even looking for one, and why in the same directory as the program? I have installed the MQ client, and afaik I have all the environmental variables, etc. set up properly.
Thanks for any help you can give
Is that an unhandled or a first chance exception? Internally, the MQ .net layer will try to read a MQClient.ini but should function quite happily without it. It reads the file for compatibility with the C client, and can handle some of the MQClient.ini stanzas. I would not have expected an absence of such a file to cause problems, but it will try to open it internally. Was that the full callstack, as I'd have expected some MQ libraries on the stack otherwise.

DBNull error - 'System.InvalidCastException'

Using Visual Studio 2008 and generating .net 2.0 framework with VB.net for a web application.
I encountered a very strange problem currently. After I build a solution and click a link in a web page, I got an error message as following. The same thing happened when I tried to run in debug mode.
*************************************** ERROR Message ******************************************************
"An exception of type 'System.InvalidCastException' occurred in Microsoft.VisualBasic.dll but was not handled in user code"
"Additional information: Operator '=' is not defined for type 'DBNull' and string "". "
*******************************************************************************************************************
The problem part is simply as below in a vb file. The value of dataview(0)(“name”) is NULL and my_name is a variable string. The strange is thing I didn't change any code in this vb file. This vb file was built previously and used for a long time ago without any problem. It just suddenly happened today. I have this syntax all over the program without causing any problem. I have tried to restore the whole solution back to original but still have the problem.
Can anyone please advise why all the sudden and how to fix?
If dataview(0)(“name”) = my_name then …
Try to determine NULL value first ..
If NOT IsDBNull(dataview(0)(“name”)) Then
If dataview(0)(“name”) = my_name then
'codes here
End If
End If

VB.Net "COMException was unhandled" Error

I have a VB.Net program written with .Net 2.0
I'm trying to write a code that logs entire registry entries into a log file.
I have got it to work wit the following code.
http://pastebin.com/kmA63cUe
However whenever I try to add an additional Registry key to log
LogPrint4("<-----------------HKLM/WebCheck-------------------->")
If reg.enumvalues(&H8000002, "Software\Microsoft\Windows\CurrentVersion\WebCheck", keys2, types) = 0 Then
If IsArray(keys2) Then
For p = 0 To UBound(keys2)
reg.getstringvalue(&H8000002, "Software\Microsoft\Windows\CurrentVersion\WebCheck", keys2(p), value)
LogPrint4(keys2(p) & "=" & value)
Next
End If
End If
It comes up with the following error
COMException was unhandled Check the ErrorCode Property of the
exception to determine the HRESULT returned by the COM object.
I'm not sure why it is limiting it only to 5 checks.
Anyone have any ideas?
Consider using the built-in Registry support instead of the COM libraries. At a minimum, you'll get clearer error messages. It is supported in .NET 2.0.
http://msdn.microsoft.com/en-us/library/microsoft.win32.registry(v=vs.80).aspx
Good luck!