Announcement

Collapse
No announcement yet.

shell command

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

  • #41
    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

    https://www.tesla.com/roadster

    Comment


    • #42
      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.

      Comment


      • #43
        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
        [I]I made a coding error once - but fortunately I fixed it before anyone noticed[/I]
        Kerry Farmer

        Comment


        • #44
          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

          Comment


          • #45

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

            Code:
            FUNCTION PBMAIN () AS LONG
             SHELL "notepad.exe"
             SHELL "write.exe"
            END FUNCTION
            https://www.tesla.com/roadster

            Comment


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

              Comment

              Working...
              X