"The directory name is invalid" error on Process.Start? - vb.net

I am writing a launcher program, and when I go to start the process I get the "The directory name is invalid" error. Here is the code that is launching the process:
Const DEBUG_ROOT = _
"Z:\Kiosk_JC\KioskSignIn.root\KioskSignIn\KioskSignIn\KioskSignIn\bin\Debug"
Dim oKiosk As New System.Diagnostics.Process
oKiosk.StartInfo.UserName = oEnc.Decrypt(Username)
oKiosk.StartInfo.Password = oEnc.DecryptSecure(Password)
oKiosk.StartInfo.Domain = oEnc.Decrypt(Domain)
''// The AddBS function appends a '\' to the passed string if it is not present
oKiosk.StartInfo.WorkingDirectory = AddBS(DEBUG_ROOT)
oKiosk.StartInfo.FileName = "KioskSignIn.exe"
oKiosk.StartInfo.UseShellExecute = False
Dim proc As Process = Nothing
proc = System.Diagnostics.Process.Start(oKiosk.StartInfo)
I saw on another question here that I needed to set the WorkingDirectory (before I started searching I was getting the error). Even though I have this property set, I am still getting the error. Any thoughts?
More info
I should also note that my Z:\ is a on my network. I have a function that resolves a path to UNC. When I ran this function on DEBUG_ROOT, I get the same error.
I tried moving the application to c:\kiosk. Same result. I am logged in as the user I am impersonating, so I have access to all shares and files.
Here is the link, for some reason the URL formating wants to consume all the text after the link is designated:
Referred Post

Mapped drives are per-user. You are likely starting the process with a different user.

Sounds like the process can't see the Z: drive or doesn't have security access. What user context does the app run under? Perhaps the Z: drive is not available in that context.

I got the same error as you do. most likely the user you use to run the process does not have access to specified resource (exe file)
try to move your exe to some other location and/or give your user access rights to the file.

Related

OpenFileDialog.InitialDirectory returns empty string instead of the path that opens in testing

I would like to point new users to the proper directory to where the file type may be found. However, I don't want to hamper the efficiency of experienced users, as there are more specific sub folders that they may wish to remain in throughout multiple file openings.
I found some context for openfileDialog for c++ here: Initial directory is not working for CFileDialog
However I am interested in a VB solution. Here is Microsoft's documentation:
https://msdn.microsoft.com/en-us/library/system.windows.forms.filedialog.initialdirectory(v=vs.110).aspx
in which they state
The InitialDirectory property is typically set using one of the following sources:
A path that was previously used in the program, perhaps retained from the last directory or file operation.
Here is my code:
If Not ImportDialog.InitialDirectory.Contains("Direct Access\Shell\Customer Invoices") Then
ImportDialog.InitialDirectory = "....\Direct Access\Shell\Customer Invoices\"
End If
How can I determine if a user would automatically be sent to this directory or a subdirectory in the tree if getting InitialDirectory is unreliable?
I saved the most recently opened folder and redirected the file path depending on if the user preferred a different path:
If _lastOpenFolder = "" Then
ImportDialog.InitialDirectory = "Direct Access\Shell\Customer Invoices\"
Else
ImportDialog.InitialDirectory = _lastOpenFolder
End If
If ImportDialog.ShowDialog = Windows.Forms.DialogResult.OK Then
_lastOpenFolder = ImportDialog.FileName.Substring(0, ImportDialog.FileName.LastIndexOf("\"))
_lastOpenFolder = _lastOpenFolder.Substring(0, _lastOpenFolder.LastIndexOf("\"))
End If

Run SAS from VBA with full access

I hope someone can help. I'm trying to build a subroutine to launch SAS from VBA. I've been doing so with SAS Workspace Manager. As I'm strolling pretty far from my comfort zone I've followed mostly what I found in these two sources. Here's what I came up with so far in VBA:
Public Sub SubmitSasProg(usrid As String, passid As String, path As String, sasprog As String, varinput As String, Optional logreturn)
Dim obWsMgr As New SASWorkspaceManager.WorkspaceManager
Dim obSAS As SAS.Workspace
Dim xmlInfo As String
Set obSAS = obWsMgr.Workspaces.CreateWorkspaceByServer("Local", VisibilityProcess, Nothing, usrid, passid, xmlInfo)
Dim obStoredProcessService As SAS.StoredProcessService
Set obStoredProcessService = obSAS.LanguageService.StoredProcessService
obStoredProcessService.Repository = "file:" & path
obStoredProcessService.Execute sasprog, varinput
If IsMissing(logreturn) Then logreturn = 100000
MsgBox obSAS.LanguageService.FlushLog(logreturn)
End Sub
And I have myself a little SAS program, let's call it "Test.sas":
%let loopTimes=3;
*ProcessBody;
data a;
do x= 1 to &loopTimes;
y=x*x*x;
output;
end;
run;
Now this line will work juste fine:
Call SubmitSasProg("myuserid", "mypassword", "somepath", "Test", "loopTimes=10")
But whenever I try to execute a SAS proceedure that modifies files/libnames etc. I'll get a either a "Invalid operation for this SAS session" or "User does not have access".
Please note that I'm using SAS locally, not on a server.
So I'm guessing that I'm not correctly logged in with my SAS worksession and lack permission. I thought that the userId and password parameters in CreateWorkspaceByServer are supposed to log me in.
So my question would be how to succesfully start the SAS session with my credentials on my local computer and have all the normal access I'd have by opening the windowed environement.
Just to clarify, this SAS process would work fine in the windowed environement:
Data _NULL_;
*x del C:\WINDOWS;
x mkdir C:\Users\Myname\Desktop\NewFolder;
run;
But it would fail with an "Invalid operation for this SAS session" code if started from VBA.
Something similar happens if I try to write SAS datasets.
I've been looking for some time now but most threads are about SAS server sessions.
Any help would be appreciated.
Well, it looks like most of my problems stem from the fact that I'm not an admin on my system.
I have managed to write datasets with the above technique given that I have write privileges on the directory with my account (duuh). Allas, the x command is stubborn and won't work lest I get myself an admin account. So, two choices to «solve» this problem:
1. Get administrator privileges.
or
2. Forget the workspace manager. Use OleObjects.
While less elegant and perhaps more time consuming upon execution (not tested) OleObject will let me use SAS to its full extent. Here is the VBA code:
Dim OleSAS As Object
Set OleSAS = CreateObject("SAS.Application")
OleSAS.Visible = True
OleSAS.Top = 1
OleSAS.Title = "Automation Server"
OleSAS.Wait = True
OleSAS.Submit(yourSAScode)
OleSAS.Quit
Set OleSAS = Nothing
If you want to run a specific process and change some macro variables as with *ProcessBody; just do OleSAS.Submit("%let "& variable_name & "=" & "yourValue") and OleSAS.Submit("%include" & your_program).
Anyway, I'm pretty sad of loosing the Log report return that I had with the Worspace Manager, it was really great for fast debugging.
Hope this was usefull.
I know that previously I've had experienced issues with SAS/Intrnet not having the required security policies setup. I can't guarantee that this will fix it, but it's somewhere to start looking:
Control Panel->Administrative Tools->Local Security Policy
Security Settings->Local Policies->User Rights Assignments->Log on as a batch job
Make sure that the account that SAS will be using to run the jobs has this right.
Also, are you saying that your test.sas program fails because it tries to write a dataset?
Also, you may be experiencing some of the same issues I've had here:
Using SAS and mkdir to create a directory structure in windows

ASP Upload Component - Classic ASP

I have just moved a site from a dedicated server to a GoDaddy shared hosting account, and have just encountered loads of problems! One being with ASP Upload.
In Classic ASP, this is what I would normally do to upload files to my folder:
Set upload = Server.CreateObject("Persits.Upload")
uploadPath = Server.MapPath("../../files/photos/"&token_&"/")
upload.IgnoreNoPost = True
upload.Save(uploadPath)
Set upload = Nothing
But since moving to GoDaddy, I get this nasty message:
This feature has been disabled by the system administrator. Use SaveVirtual instead.
I went on to ASP Upload's website documentation and I could not find SaveVirtual, only SaveAsVirtual which is where I have become unstuck.
I tried using SaveAsVirtual but it threw an error stating that I was using a physical path and I should be using a virtual path! I really don't understand this and was hoping that somebody could put me straight. My website is now deemed broken and is offline, please help.
This is what I tried before the physical/virtual path error:
Set upload = Server.CreateObject("Persits.Upload")
uploadPath = Server.MapPath("../../files/photos/"&token_&"/")
upload.IgnoreNoPost = True
upload.SaveAsVirtual(uploadPath)
Set upload = Nothing
According to the docs, the method is named SaveVirtual. It does the Server.MapPath conversion for you.
So, try:
Set upload = Server.CreateObject("Persits.Upload")
uploadPath = "../../files/photos/"&token_&"/"
upload.IgnoreNoPost = True
upload.SaveVirtual(uploadPath)
Set upload = Nothing
You already set a folder path to upload not need use like this "server.mappath"
please use below of code.
Set Upload = Server.CreateObject("Persits.Upload" )
Upload.SetMaxSize 10000000 ' Maksimum dosya büyüklüğü Byte cinsinden
Upload.OverwriteFiles = True
Path = "../../duyurular/"
Count = Upload.SaveAsVirtual(Path)
for godaddy you have to go in and change the server folder permission to read/write. Otherwise you get that error message.
well I also get encounter with this problem, I just changed the folder privileges from Go-daddy Hosting server so Any one can read or Write file from specific location
Many Thanks
Ahsan Aziz Abbasi

System.Diagnostics.Process not accepting credentials

I am trying to execute a batch file using the Process class. This code is in the middle of a larger section of code where I am using LogonUser() and WindowsIdentity.Impersonate() to impersonate the local PC admin account.
I was attempting to run a batch file within a Process, without adding credentials in ProcessStartInfo, but doing it that way caused the batch file to fail silently - no errors were raised, and expected output from the batch file never was returned (I am reading stderr and stdout asynchronously, fwiw).
I then added the credentials to ProcessStartInfo, but now I get an "Access is denied" error if I do not first call WindowsImpersonationContext.Undo(), and an "Logon failure: unknown username or bad password" error if I do call .Undo() before Process.Start(). I have triple-checked that the username/password/domain is correct, for multiple accounts.
If my code has no LogonUser() or WindowsIdentity.Impersonate() calls (and no credentials in ProcessStartInfo), then I don't have a problem with the batch file executing and output from batch file being captured.
I am able to run the batch file from the desktop successfully, either as the local admin or an arbitrary local user account. I can see its permissions show that it should be readable/executable from the accounts I am trying to run it. This is really quite the stumper; any help is appreciated.
The problem was that I needed to redirect all 3 streams; I was only redirecting 2 (out, err, not in). That basically fixed things.
Are you looking for something like this?
Process proc = new Process();
proc.StartInfo.FileName = #"C:\WINNT\notepad.exe";
proc.StartInfo.UseShellExecute = false;
proc.StartInfo.CreateNoWindow = true;
proc.StartInfo.Domain = "mydomain.com"; // Domain of IIS Computer
proc.StartInfo.UserName = "kaung"; //Administrator for that computer
System.Security.SecureString password = new System.Security.SecureString();
password.AppendChar('m'); //Password
password.AppendChar('y');
password.AppendChar('p');
password.AppendChar('a');
password.AppendChar('s');
password.AppendChar('s');
password.AppendChar('w');
password.AppendChar('o');
proc.StartInfo.Password = password;
proc.Start();

web service - web client function will not write to db

I am unable to write any records to my database using a web service. Service is set up OK and can access it via uri and also query my database via the service using a simple page i created.
When it comes to writing to the database, I am not getting any errors, and the instance of my WebClient which is populated with variables to write to the db is holding all the variables OK but when it comes to actually writing to the db (see below code) nothing seems to happen except that the Member ID of the last existing member added to the database is returned.
'assign all abMem fields to values within form to write to database
newMem.Title = ddTitle.SelectedValue
newMem.Initials = txtInitials.Text
newMem.Surname = txtSurname.Text
newMem.Address1 = txtAdd1.Text
newMem.Address2 = txtAdd2.Text
newMem.Address3 = txtAdd3.Text
'etc etc .... additional fields have been removed
Try
cc.Open()
cc.CreateMember(newMem)
returnMem = cc.GetMember(newMem)
MesgBox(returnMem.MemberID & " - Member Created")
cc.Close()
Catch cex As CommunicationException
MesgBox("CommEX - " & cex.Message)
cc.Abort()
Catch tex As TimeoutException
MesgBox("TimeEX - " & tex.Message)
cc.Abort()
Finally
MesgBox("Closed the Client")
End Try
When i run the above, I've noticed in the log file for the service (in the system32 folder on my server) that 2 requests are made each time - presumably one for where I am trying to add a record and the other I would think would be the request for the ID of this member (which isn't created, hence why I believe it it is simply returning the last successful entry in the table).
I know there isn't a problem with the actual web service as there is another user successfully able to add to the db via the service (unfortunately I am unable to simply copy their set-up as they are hitting it via a php page) so i know there is a problem somewhere in my code.
Is cc.CreateMember(newMem) the correct syntax for passing a member's details to the function in the webservice is what I am wondering?
I've re-wrote the code (seems identical to above) and republished the web service. Seems to be working OK now so I must have had some silly mistake somewhere!