Answer the question
In order to leave comments, you need to log in
How to access system classes from user class methods?
From a regular function, you can normally refer, for example, to System.Windows.Forms.Cursor
[void] [System.Reflection.Assembly]::LoadWithPartialName("System.Windows.Forms")
function getPos(){
[System.Windows.Forms.Cursor]::Position
}
getPos
IsEmpty X Y
------- - -
False 1001 460
[void] [System.Reflection.Assembly]::LoadWithPartialName("System.Windows.Forms")
class A{
static getPos(){
[System.Windows.Forms.Cursor]::Position
}
}
[A]::getPos
+ [System.Windows.Forms.Cursor]::Position
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~
Не удалось найти тип [System.Windows.Forms.Cursor].
+ CategoryInfo : ParserError: (:) [], ParentContainsErrorRecordException
+ FullyQualifiedErrorId : TypeNotFound
Answer the question
In order to leave comments, you need to log in
I don’t follow that they messed up in five, maybe just
[void] [System.Reflection.Assembly]::LoadWithPartialName("System.Windows.Forms")
Add-Type -TypeDefinition @'
using System.Windows.Forms;
using System.Drawing;
public class A{
public static Point getPos(){
return Cursor.Position;
}
}
'@ -ReferencedAssemblies 'System.Windows.Forms.dll','System.Drawing.dll'
[A]::getPos()
IsEmpty X Y
------- - -
False 1112 316
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question