Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6198983
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 24, 20262026-05-24T04:06:33+00:00 2026-05-24T04:06:33+00:00

Context I’m trying to write myself a script that would toggle my WLAN adapter

  • 0

Context
I’m trying to write myself a script that would toggle my WLAN adapter (enable/disable it) depending on a condition. The script should disable the adapter if it’s currently enabled or, conversely, enable it if currently disabled. This is what I’ve come up with so far:

Set WshShell = WScript.CreateObject("WScript.Shell")
WshShell.Run "%comspec% /C devcon status PCI\VEN_168C > C:\devstat.txt", 0, false
Return = WshShell.Run("findstr disabled C:\devstat.txt", 0, true)
WScript.Echo Return

If Return = 0 Then
        WshShell.Run "devcon " & "enable PCI\VEN_168C", 0, false
Else
        WshShell.Run "devcon " & "disable PCI\VEN_168C", 0, false
End If

Explanation of the script
Line 1 is quite obvious, so I’m skipping that part. Line 2 executes devcon to check the status of my WLAN adapter (hardware ID PCI\VEN_168C) and dump the output to C:\devstat.txt. Line 3 runs findstr to check whether C:\devstat.txt contains “disabled“. If “disabled” is not found, findstr should return errorlevel > 0, otherwise errorlevel == 0 (zero). The rest of the script is just if statements based on the value of Return (which is supposed to hold the value of errorlevel).

Problem
Value of Return is always 1 whether C:\devstat.txt contains “disabled” or not.

What am I missing here?


Final Edit
Thanks to barlop’s hint, I managed to figure out a workaround. It turns out that the culprit is Windows Scripting Host. The script has to be paused for several miliseconds after executing Line 2, so here is what the final script should look like:

Set WshShell = WScript.CreateObject("WScript.Shell")
WshShell.Run "%comspec% /C devcon status PCI\VEN_168C > C:\devstat.txt", 0, false
WScript.sleep 400
Return = WshShell.Run("findstr disabled C:\devstat.txt", 0, true)
Rem WScript.Echo Return

If Return = 0 Then
    WshShell.Run "devcon " & "enable PCI\VEN_168C", 0, false
Else
    WshShell.Run "devcon " & "disable PCI\VEN_168C", 0, false
End If
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-24T04:06:34+00:00Added an answer on May 24, 2026 at 4:06 am

    There is no problem with findstr..

    Run this code, which is the same code as yours but with wscript.echo “WAIT” just before the findstr line. Now when that wscript.echo “WAIT” line executed, open the file, you will probably see it doesn’t contain disabled, now write disabled in it, and save it. Then click OK to the message that says wait. And the program continues.

    I get the correct result, from the errorlevel returned by the findstr command. That is
    1 for when it doesn’t contain disabled
    0 for when it does

    You can also try for the sake of troubleshooting, to make the program simpler to find the error. So you could try removing that line, to test findstr, then you may have found findstr was fine. Looking at the file just before findstr, and amending it manually, shows it too without having to remove that line.

    I tried also changing Return to Retur ‘cos I thought maybe Return was a keyword and thus won’t quite work, but it works fine with the variable name of Return which you used.

    So the issue is

    WshShell.Run "%comspec% /C devcon status PCI\VEN_168C > C:\devstat.txt", 0, false
    

    but findstr is fine. And I think you were right to use True as the 3rd parameter in

    WshShell.Run(“findstr xbc C:\getmail\a.a”, 0, true)

    since from script56.chm the documentation ” If set to true, script execution halts until the program finishes, and Run returns any error code returned by the program. If set to false (the default), the Run method returns immediately after starting the program, automatically returning 0 (not to be interpreted as an error code).”

    Set WshShell = WScript.CreateObject("WScript.Shell")
    WshShell.Run "%comspec% /C devcon status PCI\VEN_168C > C:\devstat.txt", 
    
    0, false
    wscript.echo "WAIT"
    Return = WshShell.Run("findstr disabled C:\devstat.txt", 0, true)
    WScript.Echo Return
    
    If Return = 0 Then
            WshShell.Run "devcon " & "enable PCI\VEN_168C", 0, false
    Else
            WshShell.Run "devcon " & "disable PCI\VEN_168C", 0, false
    End If
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Context: I have a WPF App that uses certain unmanaged DLLs in the D:\WordAutomation\MyApp_Source\Executables\MyApp
Context: C# 3.0, .Net 3.5 Suppose I have a method that generates random numbers
In context of recent trends in interviews i have noticed that this question arises
The Context At the moment, I have a JTextArea that has been created like
Context: I'm building a little site that reads an rss feed, and updates/checks the
The context is in a Mac's Safari. I'm creating a HTML button that has
Context: I'm in charge of running a service written in .NET. Proprietary application. It
Context: So, I am attempting to build a ridiculously complex domain model. Talking with
Context : programming a c/c++ win32-mfc library How to know whether we are in
Context PHP 5.3.x Overview After doing a code-review with an associate who uses both

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.