-1

I need to adjust the below script to get Bitlocker status to a text file that should have the computer name as for its filename. So for a PC named Station10 the script would output a text file called Station10_enabled.txt. Or, if Bitlocker is disabled, it would create a file called Station10_disabled.txt.

I have below code, which seems to make sense, but is not working.

The code produces the error "Can not use parentheses when calling a sub", how can I fix that?

I also fear once the code runs the %computername% variable will not work or create a syntax error, but I can't test because of above issue.

If anyone out there knows how to gracefully handle what I am trying to do, please help.

strComputer = "." 
Set objShell = CreateObject("Wscript.Shell") 
strEnvSysDrive = objShell.ExpandEnvironmentStrings("%SystemDrive%") 

Set objWMIServiceBit = GetObject("winmgmts:\\" & strComputer & "\root\CIMV2     \Security\MicrosoftVolumeEncryption") 
Set colItems = objWMIServiceBit.ExecQuery("SELECT * FROM Win32_EncryptableVolume",,48) 

For Each objItem in colItems 
    If objItem.DriveLetter = strEnvSysDrive Then 
       strDeviceC = objItem.DeviceID 
       DriveC =  "Win32_EncryptableVolume.DeviceID='"&strDeviceC&"'" 
       Set objOutParams = objWMIServiceBit.ExecMethod(DriveC, "GetProtectionStatus") 
        If objOutParams.ProtectionStatus = "1" Then 
            My.Computer.FileSystem.WriteAllText("C:\cos\.txt","Bitlocker is enabled.",True)  
        Else 
            My.Computer.FileSystem.WriteAllText("C:\cos\test.txt","Bitlocker is disabled.",True) 
        End if 
    End If 
Next
TheBlastOne
  • 4,291
  • 3
  • 38
  • 72
  • 1
    I think you just need to remove the round brackets on lines with **My.Computer...** `My.Computer.FileSystem.WriteAllText "","",True` – PatricK Apr 29 '14 at 22:53

1 Answers1

0

VB is a bit picky about the round brackets:

Argument lists for Function calls must be specified if you use the function result.

Argument lists for Sub calls must not be specified. The same holds true for argument lists of function calls if you do not use the function result.

The pitfall is that you usually get away if you call a sub (or function, and don´t use its result) that expects exactly one parameter, and specify that parameter in round brackets. You might believe that since this works, you may (or must) specify round brackets. This is untrue, because in that case, the round brackets can be (and are) taken as part of the expression that is evaluated to deliver the value to be passed as an actual paarmeter. That is why writing

My.Computer.FileSystem.WriteAllText("C:\cos\test.txt","Bitlocker is disabled.",True) 

is syntactically invalid, while

AnyRoutineThatAcceptsOneArgument (Value) 

is okay, but exactly the same as

AnyRoutineThatAcceptsOneArgument Value

If you don´t understand that, consider

AnyRoutineThatAcceptsOneArgument ((((((((Value))))))))

which is legal, but full of useless (redundant) brackets.

So the only two context where there are round brackets around routine arguments required is:

  • Calls to functions that expect exactly one argument, and that use the function result.

In contrast to that, for Sub calls or function calls that don´t use the function result, you are not allowed to specify the brackets. The fact that in one special case, which is the routine call with only one argument, you are allowed to specify as many round brackets as you want has nothing to do with this. It just is an expression, and you can use as many (superfluous) brackts as you want.

TheBlastOne
  • 4,291
  • 3
  • 38
  • 72
  • `AnyRoutineThatAcceptsOneArgument (Value)` and `AnyRoutineThatAcceptsOneArgument ((((((((Value)))))))` aren't the same as `AnyRoutineThatAcceptsOneArgument Value`. When you don't use `Call`, parentheses around an argument force it to be passed `ByVal`, even if it's declared as `ByRef` in the procedure declaration. See this question: [ByRef and ByVal in VBScript](http://stackoverflow.com/q/1537819/113116). – Helen May 05 '14 at 06:06
  • There is nothing in the answer questioning this. – TheBlastOne May 05 '14 at 07:45