Announcement

Collapse
No announcement yet.

shell command

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

  • Paul Purvis
    replied
    Pardon my ignorance. That setting to use poweshell rather than the command prompt is not the issue, right?

    Leave a comment:


  • Mike Gorden
    replied
    Yep, you are correct. I am not sure what I did, buy yes, it fired up just fine. Thanks Mike.

    Leave a comment:


  • Mike Doty
    replied

    Notepad and wordpad work fine with Windows 10 Pro 64-bit

    Code:
    FUNCTION PBMAIN () AS LONG
     SHELL "notepad.exe"
     SHELL "write.exe"
    END FUNCTION

    Leave a comment:


  • Mike Gorden
    replied
    Here is another problem, this time with Notepad, which I don't think is supported by Windows 10 Pro. but the following code doesn't work. Also the Shell command doesn't work either I used the code Mike Doty gave me but it didn't handle this problem.

    HTML]#COMPILE EXE
    #DIM ALL
    #INCLUDE "win32api.inc"
    FUNCTION PBMAIN () AS LONG
    LOCAL iRet AS LONG
    LOCAL OpenText AS ASCIIZ * 256
    OpenText = "C:\Windows\NOTEPAD.exe C:\QCDimensionalCheck\FractionTable.txt"
    'OpenText = "NOTEPAD.exe C:\QCDimensionalCheck\FractionTable.txt"
    iRet = NotePadOpen(OpenText)

    END FUNCTION
    FUNCTION NotePadOpen(BYVAL OpenText AS ASCIIZ * 256) THREADSAFE AS LONG
    LOCAL Wow64Value AS DWORD
    LOCAL iRet AS LONG
    ON ERROR GOTO ErrorTrap
    Wow64DisableWow64FsRedirection(Wow64Value)
    iRet = ShellExecute (%NULL, "OPEN", OpenText, BYVAL %NULL, CURDIR$, %SW_SHOWNORMAL)
    Wow64RevertWow64FsRedirection(Wow64Value) 'required
    FUNCTION = 1
    EXIT FUNCTION
    ErrorTrap:
    RESUME ErrorTrapOut:
    ErrorTrapOut:
    FUNCTION = -1
    END FUNCTION
    [/HTML]
    Not sure why. I hope i just did something stupid.
    Attached Files

    Leave a comment:


  • Kerry Farmer
    replied
    Here is my silly little program to try and understand what you are all talking about.

    It seems to raise a number of issues which I am not sure some of you gurus have covered!

    Code:
    #COMPILE EXE
    #DIM ALL
    GLOBAL x AS DOUBLE
    FUNCTION PBMAIN () AS LONG
    CLS
    PRINT "Directory"
    PRINT "a";
    PRINT DIR$("C:\Windows\system32\osk.exe");   'prints blank
    PRINT "b"
    WAITKEY$
    IF ERR <> 0 THEN
        CLS
        PRINT "minus 2"
        PRINT ERR
        WAITKEY$
        END IF                            'no error
    CLS
    PRINT "Pathscan"
    PRINT "a";
    PRINT PATHSCAN$(FULL,"osk.exe");       'prints blank
    PRINT "b"
    WAITKEY$
    IF ERR <> 0 THEN
        CLS
        PRINT "minus 1"
        PRINT ERR
        WAITKEY$                          'no error
        END IF
    CLS
    PRINT "Getattr"
    PRINT GETATTR("C:\Windows\system32\osk.exe")  'prints 0   which is what you would expect - but is reading the file - or is it?!
    WAITKEY$
    IF ERR <> 0 THEN
        CLS
        PRINT "zero"
        PRINT ERR
        WAITKEY$
        END IF                              'prints error 53
    FILECOPY "C:\Windows\system32\osk.exe", "C:\Windows\system32\osk1.exe"
    IF ERR <> 0 THEN
        CLS
        PRINT "first"
        PRINT ERR
        WAITKEY$
        END IF                               'prints error 53
    x = SHELL("C:\Windows\system32\osk1.exe",1)
    IF ERR <> 0 THEN
        CLS
        PRINT "second"
        PRINT ERR
        WAITKEY$
        END IF                                'prints error 53
    END FUNCTION
    Latest PBCC and current Windows10

    [I did not know there was a screen keyboard - so I have learned something]

    Kerry

    Leave a comment:


  • Mike Gorden
    replied
    Yes, I don't want to mess with the other threads, so thread safe has been added. I will probably need this to get NotePad.exe to work as well. Thanks so much guys.
    We only use Windows 10, Pro, 64-bit. Many simultaneous running threads in all of our machine control software. Had some issues with that topic years ago. All threading seems to be stable now. With threading, the key is being careful to make sure there are no common variables shared, and threadsafe, and CS. I use many multi-dimensional arrays where one dimension is the (var) passed. Different way of doing things but it seem to be a stable way of keeping other threads from dumping it contents into variables of any other threads.

    Leave a comment:


  • Mike Doty
    replied
    Threadsafe is probably a good idea
    Code:
    #INCLUDE "win32api.inc"
    FUNCTION PBMAIN AS LONG
     'Works only with 32-bit Windows 7
     LOCAL iRet AS LONG
     iRet = SHELL("C:\Windows\system32\osk.exe",1)
     ? "Done with PB SHELL, Click to test ShellExecute"
     GetOsk
    END FUNCTION
    
    SUB GetOsk THREADSAFE
     'Works with 64-bit Windows 10, 32-bit Windows 10, 32-bit Windows 7
     LOCAL Wow64Value AS DWORD
     LOCAL zText AS ASCIIZ * 256
     Wow64DisableWow64FsRedirection(Wow64Value)
     zText = "osk.exe"
     ShellExecute (%NULL, "OPEN", zText, BYVAL %NULL, CURDIR$, %SW_SHOWNORMAL)
     Wow64RevertWow64FsRedirection(Wow64Value)
    END SUB

    Leave a comment:


  • Mike Doty
    replied

    Big catch, thank you and read about not using Enable!

    Wonder if it should be in a threadsafe function or protected with a critical section.


    Code:
    #INCLUDE "win32api.inc"
    FUNCTION PBMAIN AS LONG
    
     'Works only with 32-bit Windows 7
     LOCAL iRet AS LONG
     iRet = SHELL("C:\Windows\system32\osk.exe",1)
     ? "Done with PB SHELL, Click to test ShellExecute"
    
     'Works with 64-bit Windows 10, 32-bit Windows 10, 32-bit Windows 7
     LOCAL Wow64Value AS DWORD
     LOCAL zText AS ASCIIZ * 256
     Wow64DisableWow64FsRedirection(Wow64Value)
     zText = "osk.exe"
     ShellExecute (%NULL, "OPEN", zText, BYVAL %NULL, CURDIR$, %SW_SHOWNORMAL)
     Wow64RevertWow64FsRedirection(Wow64Value)  'required
    
    END FUNCTION

    Leave a comment:


  • Pierre Bellisle
    replied
    Hi Mike,
    If I may, do not forget about the use of Wow64RevertWow64FsRedirection in application code after Wow64DisableWow64FsRedirection, it's very important.
    See the note at Wow64DisableWow64FsRedirection

    "Note: The Wow64DisableWow64FsRedirection function affects all file operations performed by the current thread, which can have unintended consequences if file system redirection is disabled for any length of time. For example, DLL loading depends on file system redirection, so disabling file system redirection will cause DLL loading to fail. Also, many feature implementations use delayed loading and will fail while redirection is disabled. The failure state of the initial delay-load operation is persisted, so any subsequent use of the delay-load function will fail even after file system redirection is re-enabled. To avoid these problems, disable file system redirection immediately before calls to specific file I/O functions (such as CreateFile) that must not be redirected, and re-enable file system redirection immediately afterward using Wow64RevertWow64FsRedirection."

    Leave a comment:


  • Mike Doty
    replied
    The interesting thing is, I never tried compiling the standard shell command to exe …

    Compiled to d:\test\testosk.exe
    Created shortcuts to d:\test\testosk.exe from 3 operating systems
    Windows 10 64-bit
    Windows 10 32-bit (VirtualBox)
    Windows 7 32-bit (VirtualBox)

    Code:
    'Standard shell command only works here with Windows 7
    iRet = SHELL("C:\Windows\system32\osk.exe",1) 
    
    #INCLUDE "win32api.inc"  'OskTest.Bas
    FUNCTION PBMAIN AS LONG
    
     'Works only with 32-bit Windows 7
     LOCAL iRet AS LONG
     iRet = SHELL("C:\Windows\system32\osk.exe",1)
     ? "Done with PB SHELL, Click to test ShellExecute"
    
     'Works here with 64-bit Windows 10, 32-bit Windows 10, 32-bit Windows 7
     LOCAL Wow64Value AS DWORD
     LOCAL zText AS ASCIIZ * 256
     Wow64DisableWow64FsRedirection(Wow64Value)
     zText = "osk.exe"
     ShellExecute (%NULL, "OPEN", zText, BYVAL %NULL, CURDIR$, %SW_SHOWNORMAL)
    
    END FUNCTION

    Leave a comment:


  • Dave Biggs
    replied
    Mike,

    Thanks for asking but as I believe my posts are a mostly a composite of things learned from these forums, I don't expect citations

    I think that the debugger isn't nimble enough to keep up with the tricks that the OS gets up to on the 'Windows On Windows' merry go round!

    I don't use the debugger much so I'd rather the new owners keep their focus elsewhere, at least for now

    Leave a comment:


  • Mike Gorden
    replied
    To Dave B: Do you mind if I use your code in my software? I'll give reference credit, Unfortunately, I'm the only person that will ever see it. Lol. As long as it works after compiling to exe, I'm good with that. The interesting thing is, I never tried compiling the standard shell command to exe. I bet it would have worked too. Is this a debugger problem?
    HTML Code:
    #COMPILE EXE
    #DIM ALL
    
    FUNCTION PBMAIN () AS LONG
        LOCAL iRet AS LONG
        iRet = SHELL("C:\Windows\system32\osk.exe",1)
    
    END FUNCTION
    After compiling the above code to exe, it does not work. So clearly your code is the answer but would the fact that the debugger gives an error, in both cases, indicate a a problem that needs to be addressed in the next IDE release? Should I send a note to the new owners so that they will be aware of the problem?

    Leave a comment:


  • Mike Gorden
    replied
    To Dave B: When I run your code in the debugger, I get file not found error. However, when I compile to exe, the keyboard pops up over and over, no problems. So what is going on?

    Leave a comment:


  • Mike Doty
    replied
    removed screenshot of environment variables
    Last edited by Mike Doty; 5 Dec 2018, 05:36 AM.

    Leave a comment:


  • Mike Doty
    replied
    1. sfc /scannow
    2. chkdsk /f
    3. might use "everything" to search to if there are multiple copies of osk.exe
    4. see if osk.exe ended up in a quarantined folder
    5. run Malwarebytes
    6 be sure a windows update isn't in progress
    7 see if there are multiple virus checkers
    8 see if path is correctly pointing to \windows\system32
    System properties, advanced, Environment Variables

    Just brain storming ...

    Leave a comment:


  • Mike Gorden
    replied
    I Have to leave for a while. I'll be back after midnight. I always appreciate the selfless dedication all of you show. I'm always amazed.

    Leave a comment:


  • Mike Gorden
    replied
    "And what was the number in the caption title of the error 50 message box?" OSK 5

    Leave a comment:


  • Dave Biggs
    replied
    Looks like there is a problem with the PBIDE Debugger when OS redirection is in play in Win10 Pro 64bit.

    I see the same issue as Mike G when running Pierre's examples using the PB IDE Debugger in Win10 (even when ShellExecuteEx() is isolated within a pair of #DBUG CODE OFF/ON metastatements).

    I don't see that problem when running the PB IDE Debugger in Win7 Pro 64bit.

    In Win10 Pro 64Bit, the OSK is launched OK however when the IDE's Compile/Run option is selected (ie not in Debug mode).

    Here's an example that should run OK in Win10 32 or 64bit,
    Code:
    #Dim All
    #Compile Exe
    #Include "WIN32API.INC"
    
    Declare Function DisableRedirection(OldValue As Long) As Long     ' for run-time (explicit) dynamic linking to functions in 64 bit Kernel32.dll
    Declare Function ReEnableRedirection(OldValue As Long) As Long    ' that aren't available in 32 bit systems
    '------------------/
    
    Function PBMain()
     Local OSK      As String
     Local PID      As Dword
     Local OldValue As Long
     Local hKernel32, dProcAddrDis, dProcAddrEn As Dword
       OSK = "C:\windows\system32\osk.exe"
       hKernel32 = GetModuleHandle("Kernel32.dll")
    
        dProcAddrDis = GetProcAddress(hKernel32, "Wow64DisableWow64FsRedirection")    ' get subroutine address from dll
        dProcAddrEn  = GetProcAddress(hKernel32, "Wow64RevertWow64FsRedirection")
    
        If dProcAddrDis Then                                                          ' dealing with 64bit OS
          CALL DWORD dProcAddrDis USING DisableRedirection(OldValue)
            WinBeep 800,200
            SHELLEXECUTE(%HWND_Desktop, "open", "C:\windows\system32\osk.exe", "", "", %SW_Show)
          CALL DWORD dProcAddrEn USING ReEnableRedirection(OldValue)
        Else                                                                        ' 32bit OS
          pid = Shell( OSK )
        End If
    
    End Function
    '------------------/PBMain

    Leave a comment:


  • Jon Eskdale
    replied
    Mike's program in post #24 works for me - Using Windows 10 Pro 64 bit Version 1803. I think the best thing to do would be to Run Process Monitor and determine the exact cause of the error. If you need my log to compare with let me know - but it should give you the cause of the error

    Leave a comment:


  • Pierre Bellisle
    replied
    And what was the number in the caption title of the error 50 message box?

    Leave a comment:

Working...
X