LinkLabel gives error on click - Powershell


hi all

below snippet of script encountering error:

    function getloglocation($loglocation){          write-host $loglocation          $linklabel1.add_click({[system.diagnostics.process]::start($loglocation)})          $form1.controls.add($linklabel1)      }

linklabel1 linklabel want link created $loglocation.

i call above function in script , can see $loglocation value received , not null. reason below error encounter upon clicking on link:

exception calling "start" "1" argument(s): "value cannot null.
parameter name: startinfo"
at c:\users\testuser1\desktop\hyperlinkform.ps1:379 char:67
+         $linklabel1.add_click({[system.diagnostics.process]::start <<<< ($loglocation)})
    + categoryinfo          : notspecified: (:) [], methodinvocationexception
    + fullyqualifiederrorid : dotnetmethodexception

please advice mistake here.

in function if replace $loglocation other value c:\widows or $env:temp or www.microsoft.com; work fine.

$linklabel1.add_click({[system.diagnostics.process]::start($env:temp)})

awaiting suggestion.


regards ram


regards ram

you should assign $loglocation variable scope $script.

example: $script:loglocation = "c:\windows"



Windows Server  >  Windows PowerShell



Comments

Popular posts from this blog

Edit Group Policy

Hyper-V VM not reaching OS 'Logon' screen

DNS question...