?
Solved

Shelled process not working

Posted on 2012-08-22
57
Medium Priority
?
1,536 Views
Last Modified: 2012-09-03
Hi all - I am trying to launch an exe located in windows\system32 (dirquota.exe) to acquire quota information, but it fails (throws an exception when start) with "system cannot find the file specified".
I'm displaying the filename & arguments in my output, and when I take that string and copy/paste it to the command line, it works fine.
Any idea where it might be failing?

Using ShelledProcess As New Process
  With ShelledProcess.StartInfo
    .FileName = "dirquota.exe"
    .WorkingDirectory = Environment.SystemDirectory 
    .Arguments = "quota list /remote:" & ServerName & " /path:" & FolderPath
    .UseShellExecute = False
    .RedirectStandardOutput = True
  End With

  Console.WriteLine(ShelledProcess.StartInfo.FileName & " " & ShelledProcess.StartInfo.Arguments)

  Try
    ShelledProcess.Start()
    If ShelledProcess.HasExited Then
       '...other code
    End If
  Catch ex As Exception
    Console.WriteLine(ex.Message)
  End Try
End Using

Open in new window

0
Comment
Question by:sirbounty
  • 37
  • 12
  • 5
  • +2
56 Comments
 
LVL 83

Assisted Solution

by:CodeCruiser
CodeCruiser earned 252 total points
ID: 38321220
>I'm displaying the filename & arguments in my output

>Console.WriteLine(ShelledProcess.StartInfo.FileName & " " & ShelledProcess.StartInfo.Arguments)

Does that comeback with just the exe name or full exe path? Is it Win7/Vista? Could it be UAC blocking access to system folder?
0
 
LVL 86

Assisted Solution

by:Mike Tomlinson
Mike Tomlinson earned 496 total points
ID: 38321228
Try changing:

    .FileName = "dirquota.exe"

To:

    .FileName = System.IO.Path.Combine(Environment.SystemDirectory, "dirquota.exe")
0
 
LVL 67

Author Comment

by:sirbounty
ID: 38321282
Running in an elevated cmd prompt on W2k8.
The writeline returns the name only.
Trying the suggestion now...
0
Free Backup Tool for VMware and Hyper-V

Restore full virtual machine or individual guest files from 19 common file systems directly from the backup file. Schedule VM backups with PowerShell scripts. Set desired time, lean back and let the script to notify you via email upon completion.  

 
LVL 67

Author Comment

by:sirbounty
ID: 38321288
Same thing - although the writeline now displays the full path.
I can still, even with the path included, copy/paste and it works.
0
 
LVL 86

Expert Comment

by:Mike Tomlinson
ID: 38321318
What are the values of ServerName and FolderPath?
0
 
LVL 67

Author Comment

by:sirbounty
ID: 38321329
Servername is a remote server, folderpath contains the local path (of that server) to the quota object.
Thus, the command would read something like:

dirquota quota list /remote:MyServer /path:J:\UserData\JohnDoe
0
 
LVL 67

Author Comment

by:sirbounty
ID: 38321478
I've taken out the arguments, just to see if it will launch, and no go.
Next, I tried another CLI tool in system32, cacls.exe.  That launched fine, displaying the usage, as expected.
I don't get it. : \
0
 
LVL 86

Assisted Solution

by:Mike Tomlinson
Mike Tomlinson earned 496 total points
ID: 38321503
What happens with?

    Dim FileName As String = System.IO.Path.Combine(Environment.SystemDirectory, "dirquota.exe")
    If System.IO.File.Exists(FileName) Then
        MessageBox.Show("Found it!")
    Else
        MessageBox.Show("Does not exist: " & FileName)
    End If
0
 
LVL 67

Author Comment

by:sirbounty
ID: 38321543
stranger still...it's showing it's not present....
it IS there, and I can run it in that same environment with no problem.
0
 
LVL 67

Author Comment

by:sirbounty
ID: 38321559
trying it on another server...maybe there's something to this one...
0
 
LVL 67

Author Comment

by:sirbounty
ID: 38321581
nope - same result.
0
 
LVL 67

Author Comment

by:sirbounty
ID: 38321760
This, however, from the same folder in the same cmd environment works fine, so it's not a permission/rights issue...

Dim objShell: Set objShell = CreateObject("Wscript.Shell")
Dim objExec : Set objExec = objShell.Exec ("C:\Windows\System32\dirquota.exe")

Do While Not objExec.StdOut.AtEndOfStream
  strLine = objExec.StdOut.ReadLine
  wscript.echo strLine
Loop

Open in new window

0
 
LVL 67

Author Comment

by:sirbounty
ID: 38321944
Have tried various frameworks, tried bringing dirquota.exe to the current path as well (parameter is not correct was the error returned whether launched from my app or manually).

Still testing...
0
 
LVL 67

Author Comment

by:sirbounty
ID: 38322101
My last test for the day...
Created a blank project and it bombed.
This is my full code:

    Sub Main()
        Process.Start("c:\windows\system32\dirquota.exe")
    End Sub

Open in new window



Unhandled Exception: System.ComponentModel.Win32Exception: The system cannot find the file
 specified
   at System.Diagnostics.Process.StartWithShellExecuteEx(ProcessStartInfo startInfo)
   at System.Diagnostics.Process.Start()
   at System.Diagnostics.Process.Start(ProcessStartInfo startInfo)
   at System.Diagnostics.Process.Start(String fileName)
   at test.Module1.Main()

Open in new window

0
 
LVL 67

Author Comment

by:sirbounty
ID: 38324704
I'm finding similar problems (cannot find file) online, but none of the solutions seem to work for me...any other ideas/suggestions?
0
 
LVL 67

Author Comment

by:sirbounty
ID: 38325160
Have tried modifying the manifest to highestAvailable and reqireAdministrator.  Neither work.
Have tried launching the process via cmd.exe and using everything else as arguments - it simply leaves a window open stating the dirquota is not recognized as an internal or external command...arg!

It's like a mysterious environment is created that can't see part of the system32 folder...
0
 
LVL 67

Author Comment

by:sirbounty
ID: 38325167
with the shelled cmd process, the title bar reads "Administrator:...cmd.exe", so that's an elevated prompt.
However it's left in the system32 folder, and I cannot perform a dir on dirquota.exe - I can see other files in the folder.  Very bizarre!
0
 
LVL 86

Expert Comment

by:Mike Tomlinson
ID: 38325183
Wish I could give you some secret tip...but I have none.  =\
0
 
LVL 67

Author Comment

by:sirbounty
ID: 38325241
...and running whoami /all reveals that both sessions have the exact same priveleges! : \
0
 
LVL 67

Author Comment

by:sirbounty
ID: 38325258
...and if I launch explorer from that session, the file is magically there.
0
 
LVL 67

Author Comment

by:sirbounty
ID: 38325762
Difference in those two cmd window sessions (for c:\windows\system32)

Where dirquota.exe works: 2314 files/91 dirs
Where it doesn't: 1968 files/79 dirs

I can even create dirquota.exe in the session where it doesn't exist (though it's not present in the other session).  Seems that any file created in the one session doesn't appear in the other...nor vice versa.  Almost as if they were on separate devices...
However, it doesn't behave that way outside of the system32 folder.  I tried it at the root of C and can see the new test file...
0
 
LVL 96

Expert Comment

by:Bob Learned
ID: 38326297
There are a lot of comments from some heavy hitters, and if they failed, I won't hold out much hope for me *GRIN*.

How may I help (without reading every comment carefully)?
0
 
LVL 67

Author Comment

by:sirbounty
ID: 38326372
Hi sir - it seems that if I try to launch a shelled process using dirquota.exe (FSRM's CLI) to gather quota information, the shelled process does not see the executable at all.
I discovered that if I launched a cmd.exe process, there was a very large discrepancy in the number of files and folders within the system32 folder.  It's as if the shelled process is not launching with the same credentials/security context.
I can launch other applications (obviously cmd.exe, as well as cacls.exe, another one I tried).
Have tried elevation via the manifest, using the verb "runas" in my startinfo - neither of those changed anything either.

I know there's an api, but I need to be able to use this against remote servers as well, so that's out.

Ever seen this?
0
 
LVL 67

Author Comment

by:sirbounty
ID: 38326621
I have 3 windows here.
The topmost is my initial elevated session.
The other two are spawns of a shelled process (System32\cmd.exe and SysWOW64\cmd.exe).

The top window is the only one that will find the file...the other two fail.  Notice they are all elevated.  The same user ID and privileges exist on each of these sessions.

I haven't a clue why I'm seeing this behavior, but I can't believe it's gone unnoticed until now...?
dir.png
0
 
LVL 38

Assisted Solution

by:puppydogbuddy
puppydogbuddy earned 248 total points
ID: 38327079
not an expert.....couldn't resist researching the problem on the Internet (googled "Problems with use Shell in dot net").  Found this:

Shell won't work when any paths have spaces in it.

Try using the GetShortPathName API from kernel32 to get the short form
of the path. this short form of the path will be without spaces.

HTH
0
 
LVL 67

Author Comment

by:sirbounty
ID: 38327780
Thanks for the attempt, but there are no spaces anywhere in the filename nor path... c:\windows\system32\dirquota.exe is the full path.
I really think it has something to do with elevation/UAC under Windows 2008.
0
 
LVL 96

Expert Comment

by:Bob Learned
ID: 38327848
1) What type of application are you running this from?  I do remember that you were working with ASP.NET web site, and that is a partially trusted environment that can affect the call.

2) What are the directory rights for that System32 folder?  Windows 2008 Server usually tries to lock things down pretty tight, and access to the system folders are restricted by default.
0
 
LVL 67

Author Comment

by:sirbounty
ID: 38328841
1) Separate project (still dabbling on that one ;o).  I even created a brand new console app and only had the single line to start the dirquota.exe process - fails with the same error that it simply cannot find the file.

2) I'll get this when I get to work
0
 
LVL 67

Author Comment

by:sirbounty
ID: 38328912
They are the same in either session:
NT SERVICE\TrustedInstaller:F
NT SERVICE\TrustedInstaller:(CI)(IO)F
NT AUTHORITY\SYSTEM:C
NT AUTHORITY\SYSTEM:(OI)(CI)(IO)F
BUILTIN\Administrators:C
BUILTIN\Administrators:(OI)(CI)(IO)F
BUILTIN\Users:R
BUILTIN\Users:(OI)(CI)(IO)(special access:)
                          GENERIC_READ
                          GENERIC_EXECUTE

CREATOR OWNER:(OI)(CI)(IO)F

Open in new window

0
 
LVL 67

Author Comment

by:sirbounty
ID: 38329031
Now I've discovered that adding my credentials to the process throws an exception: "The requested operation requires elevation."

I have the verb "runas" defined in my startinfo, and I'm launching the process from an elevated prompt, so I'm not sure why the elevation is not passing on to the child process (I thought it was supposed to?)
0
 
LVL 96

Assisted Solution

by:Bob Learned
Bob Learned earned 1004 total points
ID: 38329045
It looks like you tried a lot of experiments, and I am not sure where you are now, so let's keep this in the back of our mind:

ProcessStartInfo.UseShellExecute Property

http://msdn.microsoft.com/en-us/library/system.diagnostics.processstartinfo.useshellexecute.aspx

When UseShellExecute is false, the FileName property must be a fully qualified path to the executable.
0
 
LVL 96

Assisted Solution

by:Bob Learned
Bob Learned earned 1004 total points
ID: 38329057
Something else to think about when you are working with UAC--Application Manifest

Step 6: Create and Embed an Application Manifest (UAC)
http://msdn.microsoft.com/en-us/library/windows/desktop/bb756929.aspx

Sample:

<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<assembly xmlns="urn:schemas-microsoft-com:asm.v1" manifestVersion="1.0"> 
  <assemblyIdentity version="1.0.0.0"
     processorArchitecture="X86"
     name="IsUserAdmin"
     type="win32"/> 
  <description>Description of your application</description> 
  <!-- Identify the application security requirements. -->
  <trustInfo xmlns="urn:schemas-microsoft-com:asm.v2">
    <security>
      <requestedPrivileges>
        <requestedExecutionLevel
          level="requireAdministrator"
          uiAccess="false"/>
        </requestedPrivileges>
       </security>
  </trustInfo>
</assembly>

Open in new window

0
 
LVL 67

Author Comment

by:sirbounty
ID: 38329105
Yep, I've tried elevation via the manifest - was using highestAvailable, but just changed to requireAdministrator.  If I'm in an elevated cmd, it doesn't prompt me, but running it otherwise, does prompt me to allow it.
I'm not quite sure I follow the prior comment - fully qualified path...the example doesn't list the usage of working directory, so I removed that, and re-ran it.   Now I'm back to "cannot find file" instead of "requires elevation".

I'll try startinfo's filename as c:\windows\system32\dirquota.exe and see what happens...
0
 
LVL 67

Author Comment

by:sirbounty
ID: 38329129
Both of these versions die with "Cannot find file specified...

      
Using ShelledProcess As New Process
  With ShelledProcess.StartInfo
    .FileName = "C:\Windows\System32\dirquota.exe"
  ' or using the following:
 '.FileName = IO.Path.Combine("c:\windows\system32", "dirquota.exe")

    .UseShellExecute = False
    .RedirectStandardOutput = True
  End With

  Try
     ShelledProcess.Start()

Open in new window

0
 
LVL 96

Expert Comment

by:Bob Learned
ID: 38329406
Here is something to chew on:  Those rights don't seem quite right (or correct, if you will):  We need to find out what the effective rights are for the user that you are using to execute the process.
0
 
LVL 67

Author Comment

by:sirbounty
ID: 38329479
Running under my credentials - I have Full Control, Delete subfolders and files, change permissions and take ownership as the only items 'not' checked for effective permissions against my account (certainly have read/write/execute on system32 folder).
0
 
LVL 67

Author Comment

by:sirbounty
ID: 38329612
Running vbscript or powershell script works fine.  I would have thought that the powershell route would fail - doesn't it use the same framework?
0
 
LVL 96

Expert Comment

by:Bob Learned
ID: 38330714
Another possibility, that I have no idea about one way or the other:

    The startup executable calls another executable (like msinfo32.exe does).
0
 
LVL 67

Author Comment

by:sirbounty
ID: 38331133
Another reason I would expect powershell to fail...
I may look into that further though - can't hurt.  I'm stuck at this point. :(
0
 
LVL 96

Assisted Solution

by:Bob Learned
Bob Learned earned 1004 total points
ID: 38331213
Try copying dirquota.exe to a different directory, to see if it is a folder security issue.
0
 
LVL 67

Author Comment

by:sirbounty
ID: 38331303
I did try that once.
I also tried including it within my project.
Both of those routes result in "the parameter is not correct" - but I think I tried just running the exe, which should produce the usage for output.  I'll try passing legitimate parameters to it, to confirm...
0
 
LVL 96

Assisted Solution

by:Bob Learned
Bob Learned earned 1004 total points
ID: 38331667
Also, what happens if you temporarily turn off UAC?  If that doesn't help, try temporarily turning off any anti-virus software.
0
 
LVL 67

Author Comment

by:sirbounty
ID: 38336371
Copying elsewhere throws an error - check the app log... but there's nothing relevant noted there.
Will have to reboot to disable UAC...I may try it on a test server, but really starting to think powershell will be the way to go.  Disappointed that I can't do this in visual studio. :(
0
 
LVL 96

Expert Comment

by:Bob Learned
ID: 38336404
Let me add that it might be possible, but UAC will always been a nasty thorn in my side.  I am not allowed to turn off UAC, so I can't test that theory on my side.
0
 
LVL 67

Author Comment

by:sirbounty
ID: 38336432
Yeah, and if that's the "solution" - I wouldn't be allowed to in a production environment either...
0
 
LVL 96

Expert Comment

by:Bob Learned
ID: 38336880
Nah, that wasn't meant to be a solution, it was meant to see if the problem is with UAC and Windows 2008 Server.  It is important for me to help you, because sure as shootin' I will get this problem sometime in the future, and it would be good to know how to handle it.
0
 
LVL 67

Author Comment

by:sirbounty
ID: 38340270
Then I will leave this open - I was going to ditch it altogether.
I need to find out which test server isn't being used so that I can reboot it...
0
 
LVL 67

Author Comment

by:sirbounty
ID: 38340999
Believe it or not cheif - it fails with UAC off (though I don't think you can 'fully' turn it off under SP2).
I just don't get it... <sigh>
0
 
LVL 67

Author Comment

by:sirbounty
ID: 38341256
And it's not that it's shelling the process that's failing.
The file doesn't exist when the code intially launches - I check that before I even run the process.  Realy weird...
0
 
LVL 67

Author Comment

by:sirbounty
ID: 38346739
Digging further - using procmon...I'm sure you're familiar with it.  How well versed are you though?  Me, not much....

Found a buffer overlow related to my app (not entirely certain what it's referring to).
But also see a few entries stating "Desired Access: Maximum Allowed" followed by "Granted Access, All Access"

Then I see a few entries denoting "File locked with only readers".  Nothing really stands out otherwise though. :(
0
 
LVL 67

Accepted Solution

by:
sirbounty earned 0 total points
ID: 38346869
Success!

Turns out I made a goof...this app is going to be designated for x64 systems.  All I needed to do was change that configuration.  Thanks for sticking it out with me. :^)
0
 
LVL 86

Expert Comment

by:Mike Tomlinson
ID: 38347117
Glad you finally figured it out!  =)
0
 
LVL 96

Expert Comment

by:Bob Learned
ID: 38347230
What was the platform for the configuration set to?  The default is Any CPU.
0
 
LVL 67

Author Comment

by:sirbounty
ID: 38351836
Dunno why, but it was set to x86.  Checked another project I'm working on and it was set to any, so I don't know why it was different here...
0
 
LVL 96

Expert Comment

by:Bob Learned
ID: 38352041
If you right-click on the solution in the Solution Explorer, and select properties, under the Configuration Properties section, you can set the platform differently for each assembly, and whether it is included in the build.

Solution Property Pages
0
 
LVL 67

Author Closing Comment

by:sirbounty
ID: 38360348
Needed to set it up as a 64-bit app
0

Featured Post

NEW Veeam Backup for Microsoft Office 365 1.5

With Office 365, it’s your data and your responsibility to protect it. NEW Veeam Backup for Microsoft Office 365 eliminates the risk of losing access to your Office 365 data.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This document covers how to connect to SQL Server and browse its contents.  It is meant for those new to Visual Studio and/or working with Microsoft SQL Server.  It is not a guide to building SQL Server database connections in your code.  This is mo…
Today I had a very interesting conundrum that had to get solved quickly. Needless to say, it wasn't resolved quickly because when we needed it we were very rushed, but as soon as the conference call was over and I took a step back I saw the correct …
In a question here at Experts Exchange (https://www.experts-exchange.com/questions/29062564/Adobe-acrobat-reader-DC.html), a member asked how to create a signature in Adobe Acrobat Reader DC (the free Reader product, not the paid, full Acrobat produ…
With just a little bit of  SQL and VBA, many doors open to cool things like synchronize a list box to display data relevant to other information on a form.  If you have never written code or looked at an SQL statement before, no problem! ...  give i…
Suggested Courses
Course of the Month17 days, 1 hour left to enroll

864 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question