WMI gives Generic Failure when using non-admin user for class Win32_DiskDrive - wmi

I have gave appropriate permission for non admin account also user is added in "Distributed COM Users" group.
When trying to access Win32_DiskDrive or Win32_DiskDriveToDiskPartition class, I'm getting Generic Failure error. Is any extra permission is required?
Same is working, if I'm using admin account.
Other class like Win32_NetworkAdapterConfiguration giving result using non-admin account
if (!String.IsNullOrWhiteSpace(username) && !String.IsNullOrWhiteSpace(password))
{
ConnectionOptions connectionOptions = new ConnectionOptions
{
Impersonation = ImpersonationLevel.Impersonate,
Authentication = AuthenticationLevel.PacketPrivacy,
Timeout = TimeSpan.FromSeconds(60),
Username = username,
Password = password
};
var managementScope = new ManagementScope(#"\\" + assetNameOrIpAddress + #"\root\cimv2", connectionOptions);
managementScope.Connect();
managementObjectSearcher.Scope = managementScope;
}

You should add the right privileges
ConnectionOptions connOptions = new ConnectionOptions();
connOptions.Impersonation = ImpersonationLevel.Impersonate;
//Add AuthenticationLevel that suits your need
connOptions.Authentication = AuthenticationLevel.PacketPrivacy;
connOptions.EnablePrivileges = true;
ManagementScope scope =
new ManagementScope("MANAGEMNET_PATH"
, connOptions);
scope.Connect();
ObjectQuery query = new ObjectQuery(
"YOUR QUERY");
ManagementObjectSearcher searcher =
new ManagementObjectSearcher(scope, query);

Related

can i change user model credentials in loopback?

I am building an API for login and registration using loopback framework.
Loopback provides, by default, model User for login, register and other similar stuff. Default way to provide user's credentials in LoopBack is username-password/email-password but I want to use mobileNo-password/email-password as user's login credentials. So how can I do that? How can I change default credential option in User model?
You can achieve that in two ways:
If not using username field in User model, you can use it to store mobile number, mobileNo.
You have to edit user.js to accept mobileNo field as login credentials. User.login and User.normalizeCredentials are used for login process, so you can edit them like provided in the code snippet.
Note: Don't forget to add mobileNo to user.json
User.normalizeCredentials method
`User.normalizeCredentials = function(credentials, realmRequired, realmDelimiter) {
var query = {};
credentials = credentials || {};
if (!realmRequired) {
if (credentials.email) {
query.email = credentials.email;
} else if (credentials.mobileNo) {
query.mobileNo = credentials.mobileNo;
}
} else {
if (credentials.realm) {
query.realm = credentials.realm;
}
var parts;
if (credentials.email) {
parts = splitPrincipal(credentials.email, realmDelimiter);
query.email = parts[1];
if (parts[0]) {
query.realm = parts[0];
}
} else if (credentials.mobileNo) { //added mobileNo.
parts = splitPrincipal(credentials.mobileNo, realmDelimiter);
query.mobileNo = parts[1];
if (parts[0]) {
query.realm = parts[0];
}
}
}
return query;
};`
User.login method
`User.login = function(credentials, include, fn) {
.
.
.
.
.
if (!query.email && !query.mobileNo) {
var err2 = new Error('Mobile number or email is required');
err2.statusCode = 400;
err2.code = 'MOBILE_NUMBER_EMAIL_REQUIRED';
fn(err2);
return fn.promise;
}
}`

Add recipients to existing recipient list with C# code - Sitecore Email campaign manager

I want to add new recipients to existing recipientlist using code. I tried with below code but it didnt work.
TargetAudience recipientList = Factory.GetTargetAudience("RecipientListId");
if ((recipientList != null))
{
Contact contact = //I dont know how to create object for this, because it is protected class
contact.Profile.Email = "my Email";
contact.Profile.Name = "My Name";
contact.Profile.FullName = "Full Name";
recipientList.Subscribers.Add(contact);
}
Please help me to acheive this,
Thanks in advance
You can get a contact from the username of the user.
This method gets the contact by email address and contains code to get the username from the email address.
public Contact GetContact(string email)
{
// managerRoot is the top level ECM item
ManagerRoot managerRootFromId = Factory.GetManagerRootFromID(managerRoot.ID.ToString());
var username = Util.AddressToUserName(email);
string commonDomain = managerRootFromId.Settings.CommonDomain;
string fullName = commonDomain + "\\" + Util.AddressToUserName(username);
if (User.Exists(fullName))
{
return Contact.FromName(fullName);
}
return null;
}
You should then be able to add the Contact to the subscription list.
Or once you have the Contact you can set the profile values and use the subscribe method.
contact.InnerUser.Profile["Fullname"] = string.Format("{0} {1}",person.Firstname,person.Surname);
contact.Subscribe(subscriptionLists);
You can also add ECM users by using the following code supplying the email address as the localname.
protected static Contact CreateAnonymousECMUser(string localName, ManagerRoot root)
{
Contact contact = (Contact)null;
if (root != null && !string.IsNullOrEmpty(localName))
{
string commonDomain = root.Settings.CommonDomain;
Assert.IsNotNullOrEmpty(commonDomain, EcmTexts.Localize("The Common Domain setting is not set.", new object[0]));
string str = commonDomain + "\\" + Util.AddressToUserName(localName);
while (User.Exists(str))
str = str + "_";
string password = new PasswordGenerator()
{
MinimumCharacters = 14
}.Generate();
System.Web.Security.Membership.CreateUser(str, password, localName);
contact = Contact.FromName(str);
contact.Profile.ProfileItemId = root.Settings.SubscriberProfile;
contact.Profile.Save();
}
return contact;
}

Establishing session for Acumatica web services

Establishing session for Acumatica web services
I have a requirement where a session is to be established using web services, and then use that session to perform subsequent actions. E.g. Creating SOOrder and Shipment using web services using a previously created session/token.
SOOrder.Screen content = new SOOrder.Screen();
content.Url = InstanceUrl + “/Soap/SO301000.asmx";
content.CookieContainer = new System.Net.CookieContainer();
SOOrder.LoginResult lresult= content.Login(Username, password);
Using this, I have already obtained a session in lresult.Session.
Now, I would like to use this session in below shipmentcontent without calling login again.
SOShipment.Screen shipmentcontent = new SOShipment.Screen();
shipmentcontent.Url = InstanceUrl + "(W(3))/Soap/SO302000.asmx";
shipmentcontent.CookieContainer = new System.Net.CookieContainer();
shipmentcontent.Login(Username, password);
By package various screens in Web Services (SM.20.70.40) found under System -> Integration -> Configure -> Web Services you create a single end-point for all these screens. Consume this service end-point in you app, login only once and call out to all those screens.
thnx
If I understand you corectly you want to persist your login connection between different actions in Acumatia. In order to achieve this, I used the following approach:
Create graph:
public class Importer : PXGraph
{
}
Inside graph created following code:
public string GetHostUrl()
{
var nextIndex = HttpContext.Current.Request.Url.ToString().IndexOf("/", 7, StringComparison.Ordinal) + 1;
var urlStart = HttpContext.Current.Request.Url.ToString().IndexOf("/", nextIndex + 1, StringComparison.Ordinal);
var url = HttpContext.Current.Request.Url.ToString().Substring(0, urlStart);
return url;
}
public Screen Screen
{
get
{
var context = new Screen
{
CookieContainer = new CookieContainer(),
AllowAutoRedirect = true,
EnableDecompression = true,
Timeout = 1000000
};
var nextIndex = HttpContext.Current.Request.Url.ToString().IndexOf("/", 7, StringComparison.Ordinal) + 1;
var urlStart = HttpContext.Current.Request.Url.ToString().IndexOf("/", nextIndex + 1, StringComparison.Ordinal);
context.Url = HttpContext.Current.Request.Url.ToString().Substring(0, urlStart) + "/Soap/IMPORTET.asmx";
return context;
}
}
and then between different screens shared context of the Screen.
For example like this:
var scr = Screen;
var userName = PXAccess.GetUserName();
var password = GetUserPassword();
var context = Screen;
var lgRes = context.Login(userName, password);
but I preserved user password between different sessions

Access Token Infinite Renewal

I am coding a social management tool. I need infinite access token for Facebook.
First please tell me if I understand this correctly;
Access Token the reason we get is for to be able to have users account permissions to application, and this Access Token has 60 days to expire. but even after that expired still user accounts permissions on application only we don't have permission to reach it?
Can I renew access token after expired? I tried something like this;
void GetToken()
{
try
{
WebClient webClient = new WebClient();
String fb_exchange_token = null;
fb_exchange_token = ds.Tables[0].Rows[0]["token"].ToString();
String newToken = fb_exchange_token;
var fb = new FacebookClient();
try
{
dynamic result = fb.Get("oauth/access_token", new
{
client_id = client_id,
client_secret = client_secret,
grant_type = "fb_exchange_token",
fb_exchange_token = fb_exchange_token
});
}
catch (Exception ex)
{
if (ex.Message.Contains("expired"))
{
dynamic result = fb.Get("oauth/access_token", new
{
client_id = client_id,
client_secret = client_secret,
grant_type = "client_credentials",
fb_exchange_token = fb_exchange_token
});
newToken = (string)result.access_token;
if (newToken != fb_exchange_token)
SqlHelper.ExecuteNonQuery(ConnectionString, "SocialTokenUpdate", ds.Tables[0].Rows[0]["SocialId"].ToString(), newToken);
}
DataProvider.ExceptionLogAdd("xx.aspx", "GetToken", ex.Message);
}
Session["Token"] = newToken;
Session["FBPageId"] = ds.Tables[0].Rows[0]["SocailFBId"].ToString();
}
catch (Exception ex)
{
DataProvider.ExceptionLogAdd("xx.aspx", "GetToken", ex.Message);
}
}
If you want to generate new accessToken automatically means Let the application open the first screen where user gives access to Application. Then it will generate new accessToken. If accessToken is Expired get it in OAuthException and redirect to front screen.

Consuming NetSuite service in WP7, CookieContainer not working

I'm using NetSuite webservice in my WP7 project.
This is the link that I use (the newer version):
https://webservices.na1.netsuite.com/wsdl/v2012_1_0/netsuite.wsdl
This worked perfectly in my C# console application, but not in WP7.
In WP7, it logs in successfully, but when adding anything (employee, customer, timebill, ...) I get the following error:
"Your connection has timed out. Please log in again"
UPDATE:
this is my console code:
NetSuiteService service = new NetSuiteService();
service.CookieContainer = new CookieContainer();
Passport passport = new Passport();
passport.account = "TSTDRVxxxxxx";
passport.email = "hamzeh.soboh#para-solutions.com";
RecordRef role = new RecordRef();
role.internalId = "3";
passport.role = role;
passport.password = "passxxxx";
Status status = service.login(passport).status;
and the following is my WP7 code:
NetSuitePortTypeClient service = new NetSuitePortTypeClient();
// service.CookieContainer = new CookieContainer();
Passport passport = new Passport();
passport.account = "TSTDRVxxxxxx";
passport.email = "hamzeh.soboh#para-solutions.com";
RecordRef role = new RecordRef();
role.internalId = "3";
passport.role = role;
passport.password = "passxxxx";
service.loginAsync(passport);
uncommenting the second statement causes a runtime error.
Try without cookies, something like this:
// Instantiate the NetSuite web services
netSuiteService = new DataCenterAwareNetSuiteService(*yourAccountNumber*);
netSuiteService.Timeout = 1000 * 60 * 60;
var appInfo = new ApplicationInfo();
//App info from application netsuite
appInfo.applicationId = *yourApplicationId*;
// Prepare login credentials for request level login
netSuiteService.passport = new Passport()
{
email = yourEmail*,
password = *yourPassword*,
account = *yourAccountNumber*
};
netSuiteService.applicationInfo = appInfo;
Prefs = new Preferences();
netSuiteService.preferences = Prefs;
SearchPreferences = new SearchPreferences();
netSuiteService.searchPreferences = SearchPreferences;
Prefs.warningAsErrorSpecified = true;
Prefs.warningAsError = false;
SearchPreferences.bodyFieldsOnly = false;