BookmarkSubscribeRSS Feed
ShuguangSun
Calcite | Level 5

I tried to using powershell to call SAS via COM. However it doesn't work in some situation.

 

I have a SAS installed on a remote windows machine with no SAS Integration Technologies (e.g. no IOM access or sas EG access or metadata server or no workspace server). When I login in via windows remote desktop, I can run sas code via COM in vscode. But if I sign in by SSH, I have the same error report as you reported.

 

 

Below I tried step by step powershell script in the ssh terminal, an error throwed in `$objSAS.LanguageService.Submit`

$objFactory = New-Object -ComObject SASObjectManager.ObjectFactoryMulti2
$objServerDef = New-Object -ComObject SASObjectManager.ServerDef
$objServerDef
$objServerDef.MachineDNSName = "xxx.xx.x.x" # SAS Workspace node
$objServerDef.Port = 0 # workspace server port
$objServerDef.Protocol = 0 # 0 = COM protocol
$objServerDef

# Class Identifier for SAS Workspace
$objServerDef.ClassIdentifier = "440196d4-90f0-11d0-9f41-00a024bb830c"

# create and connect to the SAS session
$objSAS = $objFactory.CreateObjectByServer(
"Local", # server name
$true,
$objServerDef, # built server definition
"", # user ID
"" # password
)

$program = "proc sql; create table work.test as select* from perm.data; proc print data=work.test;run;"

$objSAS.LanguageService.Submit($program);

$objSAS.Close()

An error raised after `$objSAS.LanguageService.Submit($program)`

You cannot call a method on a null-valued expression.
+ $objSAS.LanguageService.Submit($program);
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : InvalidOperation: (:) [],RuntimeException
+ FullyQualifiedErrorId : InvokeMethodOnNull

 

**Environment:**
Client OS: Windows 2019
SAS version: SAS 9.4 with ITC only, but not IT (e.g. IOM not enabled)

 

9 REPLIES 9
gwootton
SAS Super FREQ
After you run the $objSAS definition, if you echo it does it have a listing for LanguageService? Do you see a SAS program running in the background?

PS C:\Users\grwoot> $objSAS = $objFactory.CreateObjectByServer("Local",$true,$objServerDef,"","")
PS C:\Users\grwoot> $objSAS

LanguageService : System.__ComObject
DataService : System.__ComObject
FileService : System.__ComObject
ODS : System.__ComObject
Utilities : System.__ComObject
Name : SAS Workspace
UniqueIdentifier : 26C88ED3-72A2-4E78-933C-CB445314AB2B

PS C:\Users\grwoot> ps |findstr "sas"
2397 38 15792 36568 1020 0 lsass
414 40 30600 35264 0.22 25648 1 sas
PS C:\Users\grwoot> $objSAS.Close()
PS C:\Users\grwoot> ps |findstr "sas"
2399 38 15888 36664 1020 0 lsass
PS C:\Users\grwoot>
--
Greg Wootton | Principal Systems Technical Support Engineer
ShuguangSun
Calcite | Level 5

No SAS instance. The service is empty.

LanguageService  :
DataService      :
FileService      :
ODS              :
Utilities        :
Name             : SAS Workspace
UniqueIdentifier : 866FB099-92A3-4445-9C7F-5C137534D265

 

Remote powershell policy

# Get-ExecutionPolicy -list

        Scope ExecutionPolicy
        ----- ---------------
MachinePolicy       Undefined
   UserPolicy       Undefined
      Process       Undefined
  CurrentUser    RemoteSigned
 LocalMachine    RemoteSigned
gwootton
SAS Super FREQ
Seems like something is blocking your ability to start a process when signed in remotely. Do you have "Log on as a Batch Job" privilege on the remote host? Do you see any errors in the Event Viewer?

Windows Privileges
https://go.documentation.sas.com/doc/en/bicdc/9.4/bisecag/p1uhz7klzwwvr8n1r51h0nhcw2zm.htm
--
Greg Wootton | Principal Systems Technical Support Engineer
ShuguangSun
Calcite | Level 5

We have a 'sasusers' group on the windows 2019 server, and I'm in the group.

I can schedul task via SSH, like:

schtasks /create /tn %USERNAME%_test_sas /tr C:\Users\%USERNAME%\run_getopts.bat /sc once /sd 2023/12/13 /st 00:46 /ru %USERNAME% /rp

 

We use SAS OA last week and now switch to SAS foundation. The powershell code worked before, but doesn't work after we switched to SAS foundation. We should have ITC (no metadata sever) as the code works with COM when I login via Remote Desktop.

gwootton
SAS Super FREQ
If this process stopped working when you moved to not having Integration Technologies I would suspect that as the cause, its odd that we aren't getting an error from the CreateObjectByServer call. Did you see anything in the Windows Event Viewer?
--
Greg Wootton | Principal Systems Technical Support Engineer
ShuguangSun
Calcite | Level 5

I can't find anything related in the Windows Event Viewer.

ShuguangSun
Calcite | Level 5

I run the same simple powershell code as below in remote ssh and remote desktop and there are some difference in $objServerDef.

 

Code:

 

$objFactory = New-Object -ComObject SASObjectManager.ObjectFactoryMulti2
$objServerDef = New-Object -ComObject SASObjectManager.ServerDef
$objServerDef

 

SSH: (not stable, sometimes it include `ServiceName:sasobjspawn`, `port : 0`, but other times may not)

Protocol                   : 0
Description                :
DomainName                 :
LogicalName                :
BridgeEncryptionLevel      : 0
BridgeEncryptionAlgorithm  :
RecycleActivationLimit     : 0
RunForever                 : True
ShutdownAfter              : 3
ClassIdentifier            : 440196D4-90F0-11D0-9F41-00A024BB830C
ProgID                     : SAS.Workspace.1.0
ID                         :
URI                        : iom://localhost;COM;CLSID=440196D4-90F0-11D0-9F41-00A024BB830C,ENCRLVL=None/
ExtraNameValuePairs        :
BridgeSecurityPackage      :
BridgeServicePrincipalName :
BridgeSecurityPackageList  : Kerberos,NTLM
AuthenticationService      :

 

Remote Desk:

Port                       : 0   
ServiceName                : sasobjspawn
Name                       :
MachineDNSName             :
Protocol                   : 0
Description                :
DomainName                 :
LogicalName                :    
BridgeEncryptionLevel      : 0
BridgeEncryptionAlgorithm  :
DCOMSecurityService        : 0
DCOMAuthenticationLevel    : 0
MaxPerObjectPool           : 10
RecycleActivationLimit     : 0
RunForever                 : True
ShutdownAfter              : 3
ClassIdentifier            : 440196D4-90F0-11D0-9F41-00A024BB830C
ProgID                     : SAS.Workspace.1.0
ID                         :
URI                        : iom://localhost;COM;CLSID=440196D4-90F0-11D0-9F41-00A024BB830C,ENCRLVL=None/
ExtraNameValuePairs        :
BridgeSecurityPackage      :
BridgeServicePrincipalName :
BridgeSecurityPackageList  : Kerberos,NTLM
AuthenticationService      :
ProxyList                  : {}

 

gwootton
SAS Super FREQ
In checking with another resource here they advised that if the current thread has a SECURITY_NETWORK Security Identifier (SID), it is considered remote and Integration Technologies must be licensed, so this is probably what is happening when you connect via SSH, and why it worked previously.
--
Greg Wootton | Principal Systems Technical Support Engineer
ShuguangSun
Calcite | Level 5

Thanks. Will check with SAS admin.

suga badge.PNGThe SAS Users Group for Administrators (SUGA) is open to all SAS administrators and architects who install, update, manage or maintain a SAS deployment. 

Join SUGA 

Get Started with SAS Information Catalog in SAS Viya

SAS technical trainer Erin Winters shows you how to explore assets, create new data discovery agents, schedule data discovery agents, and much more.

Find more tutorials on the SAS Users YouTube channel.

Discussion stats
  • 9 replies
  • 1160 views
  • 0 likes
  • 2 in conversation