You can use QCUtil.CurrentTestSetTest to check. If it is run locally, the value will be blank. If it's being run from ALM, the value will be [1].
QCutil.IsConnected will return true if connected, false if not.
Dim CurrentTSTest
If qcutil.IsConnected Then
Reporter.ReportEvent micPass,''Connected to QC'', ''Connected to Quality Center Server: '' & qcutil.QCConnection.ServerName & vbcrlf & _
''Project : '' & qcutil.QCConnection.ProjectName & vbcrlf & '' Domain : '' & qcutil.QCConnection.DomainName
Set CurrentTSTest = qcutil.CurrentTestSetTest
if CurrentTSTest is Nothing then
Reporter.ReportEvent micFail,''IsExecutedFromQC'', ''QTP is connected to quality center server. But the test is **not** executed from a Testlab in QC''
IsExecutedFromQC = FALSE
else
Reporter.ReportEvent micPass,''IsExecutedFromQC'', ''The test is executed from a Testlab in QC''
msgbox CurrentTSTest.Name
IsExecutedFromQC = TRUE
end if
else
Reporter.ReportEvent micDone,''IsExecutedFromQC'', ''QTP is not connected to quality center server''
IsExecutedFromQC = FALSE
end if