Vb.Net win forms application not running on all computers - vb.net

I have wrote a win forms application in VB that requires some external DLLs, It installs and runs flawlessly on several machines but it does not work on one laptop! I even put Filestreams to write exceptions to a text file. While it writes intended header text to the debug file on other computers, it does not write anything to the debug file on the aforementioned laptop. My guess is that it does not even reach Form1_Load() method.
This is the structure of the program:
Import namespaces from external programs
Public Class MyApp
''Varibale declarations:
Structures and classes based on DLLs
Other declarations based on .Net Objects
Stream writer declaration and initialization for the debug file
Private Sub Form1_Load(...)
Try
Write Start and time to the debug file
execute commands
catch
write debug info
end Try
End Sub
Other events and subs
End Class
IS there a way to see what happens between the initialization of the debug file and execution of Form1_Load() ??
As I said it works perfectly on all the machines that use this except one!!
What are the things that I need to check on that machine?

Chances are that the user of the laptop is not in the Administrators group and you're trying to write to the application program folder.

Have you tried to add a placeholder line in the debug file immediately after initialization, to check that the file is actually write-able?
Is the Form's constructor reachable? If you move the "Write Start and time to the debug file" code to the constructor, does it write anything?

Related

Call an external program to run as standard user from a requiredAdministrator program

My Visual Basic program will copy files to a program files folder, so I have to use requiredAdministrator privileges since asInvoker won't allow to write in the program files folder.
After I copy the files I invoke an AutoIt script automating setup of files within the external program (for that the script calls the external program to start automation). The program that creates and copies the files to the "end" program functions fine. The script that calls the "end" program and does the automatic setup also works.
When I combine the 2 the "end" program (which I didn't write nor have the source code of) behaves erratically when run as admin (doesn't read the database or the needed files return an error and terminates itself). So run as admin is not an option. But since my program has to run as admin it looks like it passes the sames privileges to the AutoIt script which calls the "end" program as admin as well. It also happens if I call the "end" program from my app instead of the AutoIt script.
Is there any way to demote my app from admin to standard user after it copies the files, right before it calls either the AutoIt script or the "end" program so that the "end" program is not run as admin or a parameter that specifically makes the app to call the external program as standard user?
I'm using Process.start("autoitscript.exe") to call it. Or any other workaround that doesn't involve the AutoIt script calling the "end" program and my app because that works but not as I intent.
This is a tricky task to perform, but how about this:
Have your application start asInvoker, don't show any windows, and make check if it runs with elevated privileges using this code:
Public Shared Function IsAdministrator() As Boolean
Return (New WindowsPrincipal(WindowsIdentity.GetCurrent())).IsInRole(WindowsBuiltInRole.Administrator)
End Function
If it's not running with elevated privileges make it start an invisible cmd instance where you redirect the standard input.
Get the cmd process's PID and now start a new instance of your application with elevated privileges (can be done by setting StartInfo.Verb = "runas") and pass the PID as a command-line parameter.
Now your new instance of the app starts and IsAdministrator() should return True.
So now that you know that your app has administrator privileges you can check if the app has a command-line parameter that is parsable to an Integer. If so, store that Integer somewhere and then do all your admin-required work.
In the end where you want to start the autoitscript.exe application you create a process variable and assigns Process.GetProcessById(<your PID Integer here>) to it.
For example:
Dim cmdProcess As Process = Process.GetProcessById(cmdPID)
Now that you have control over the cmd instance again you just have to write to it's standard input (this article describes a little how it works).
You want to write two lines. The first is to start the other application:
autoitscript.exe
and the second is to close the cmd instance:
exit
If anything's unclear just let me know.

running code after application is closed?

i have the following problem. i am working on an auto update in my application which means i want to re-download the application. i am using DownloadFile method for this but the problem is of course i cannot download and exchange the file with my current application as long as the application is running and i can't run code after it's closed either.
this is what i am basically trying to do for ppl still didn't get my problem:
Private Sub closeApp()
Application.Exit()
' DOWNLOAD FILE AFTER PROGRAM CLOSED
End Sub
The way this is usually done is to have 2 separate programs. One is the program its self, the other is the updater. When you exit the program you spin up a copy of the updater and exit the actual program. the updater program is then free to download and overwrite the main application because the file isn't in use any more.
This can also be reversed, with the updater, sometimes called the "launcher" when used this way, acting as a stub that checks for updates to the main application when it starts. Once it sees that no update is needed, or after it updates the main program, it goes on to launch the main program and exits its self.

VS2010 vb.NET: System.invalidOperationException: the 'Microsoft.ACE.OLEDB.12.0' provider is not registered at the local machine

Good morning.
I'm in the process of writing a vb.NET forms application that will read in a selection of .xlsX files and import their contents into a SQL2012 database. Because the files are in different folders and are all formatted differently, I'm having to write it so that each folder's contents is handled by its own dedicated module. However, one thing that's common across each folder is the process that I need to go through, which is to open each file, read its contents into a DataTable, carry out any manipulation required (i.e. removing empty rows) and then run a SqlBulkCopy to load the data into SQL before moving the original file into an archive location.
So far, so good. I've written and successfully run three of these modules, but the fourth one is giving me the error that's detailed in the Title of this post - the exception is thrown at the point where I'm trying to open the connection string to the Excel object. Again I stress that I've done this three times before, and each time has been successful.
Also, I've noticed that the exception only occurs when running the code in Debug mode. If I run it in Release mode it works without any complaints.
I'm developing this application in a 64-bit environment (VS2010 on Windows 8.1), but targeting the application to x86. I'm happy to continue writing in Release rather than Debug mode, but I'm curious as to why it works in one but not the other and I'd like to be able to code for both modes if at all possible.
TIA

VB Net throws exception after saving to network drive

I am writing a VB.net program which was supposed to access an API and download some data. But I'm having some trouble with even just the basics. I have this simple program:
Public Class Form1
Private Sub Form1_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
Dim webClient As New System.Net.WebClient
Dim result As String = webClient.DownloadString("http://www.myexternalip.com/raw")
Debug.WriteLine(result)
End Sub
End Class
As expected, the program runs and prints my external IP -- but only if i do not save the program! Once I save the program to our school's network file server, the program stops working:
A first chance exception of type 'System.Net.WebException' occurred in System.dll
The program itself is exactly the same. Yet all of a sudden, after saving the program to my network folder, it breaks. I have never had this problem before and have been using the network file server for the past 6 months to do VB.net programs.
Not unsurprisingly, if I make a new program (again, not saving) and copy and paste the "broken" code into the new program, it runs fine. Then I save it and it throws an exception.
My questions:
Does this have to do with references? Possibly can the program not find the reference to System.Net? However I have never had a problem with references before.
I am at a high school. Could this have something to do with computer restrictions? Unfortunately there is little information I could provide in this regard. But it seems unlikely that a simple school file server could be causing this behavior.
Also, does this belong on another stack exchange? Maybe super user?
Thanks.
This sounds like you're running into an issue with Code Access Security. By default, .Net Framework versions 2.0 through 3.5 will not trust code located on file shares for execution. .Net Framework version 3.5sp1 set this back to something more sane, but it's still something you need to watch for.
What you can do as a quick work-around is to write a batch file that copies the file from the network share to the local system, and then kicks off the copied program. The more robust work-around is to change the code access security settings on the system, typically at the group policy level.

VB .NET run without form and without UAC when /q argument passed

I'm VERY new at VB .NET and have recently downloaded MS Visual Studio Express 2012. I'm trying to design an application to replace a VBScript I created and can't find the answer to Two of the main design phase features I require so I apologize ahead of time for my ignorance.
I'm trying to create an application to edit the configuration parameters of an existing application I support. the configurations are edited in both the Files System and in the Windows Registry.
I'm looking for a way to pass a "/q" or "/quiet" and allow the application to run silently. I have developed the program far enough to edit the options in the form and save them. I can run code (so far only messages displaying the options) from the start configuration button from a "Windows Form Application".
I'm also needing to make sure that when running silently the application does not need UAC elevation. In the original VBScript I need to elevate UAC when editing the Windows Registry.
I know this is a lot to ask for with my current knowledge level. But I'm still in the design stage and trying to learn fast and really need to know if this is even possible before I go too far.
If the original application required UAC elevation to edit the registry then the new one will too. The level of access is on a per user basis not a per application basis so unless you run the application as a different user you will have the same problem with your new application.
As to running without showing the form you will need to edit Main something like this:
<STAThread()> _
Shared Sub Main()
' Read the arguments
' Starts the application.
if (argument == "/q" or argument == "/quiet") then
' Edit the other program configurations here
else
Application.Run(New Form1())
End if
End Sub
You can call a version of Run(ApplicationContext ) that doesn't show a form, but as the starts the message loop you'd still need some way of actually editing the other program's configuration, perhaps in response to key strokes.